I have a model called Company, and in the Show view have the following:
<div id = 'tags'>
<strong>Tags:</strong>
<% unless @company.tag_list.empty? %>
<%= @company.tag_list %>
<% end %>
<% form_remote_tag(:url => {:action => 'update'},
:update => 'tags') do %>
<%= text_field :company, :tag_list %>
<%= submit_tag 'Save' %>
<% end %>
</div>
I am using acts_as_taggable_on gem.
This is the update method in the Company controller:
def update
@company = Company.find(params[:id])
if @company.update_attributes(params[:company])
flash[:notice] = "Successfully updated company."
redirect_to @company
else
render :action => 'edit'
end
end
I guess my desired result would be I could add tags, see them added via ajax, all without needing to Edit the model but from the show View, kind of like the way you can add tags in Wordpress.
UPDATE: This is the error I get (it looks like it isn't using the update action:
POST http://localhost:3000/companies/10
No action responded to 10. Actions: create, destroy, edit, email_this_week, index, new, show, and update
Hmmm, not sure why it is doing that....it should do update action, right? Do I need to do something in my routes (even though I specified the action?)