In the view:
<%= form_for event, :remote => true do |f| %>
<p class="bottom small"><%= f.select :status, Event::STATUSES, { :prompt => 'Mark as:' }, :class => 'status_update' %></p>
<% end %>
Then, my JQuery to submit form on change:
<script type="text/javascript" charset="utf-8">
$(function() {
$('.status_update').live('change', function() {
$(this).parents('form:first').submit();
});
});
</script>
In my controller:def update
@event = Event.find(params[:id])
@event.attributes = params[:event]
parse_time_and_duration if params[:starts]
@event.save
respond_to do |format|
format.html
format.json do
render :json => { :id => @event.id, :title => @event.display_title }
end
end
end
When I do this, I get a missing template error:
Missing template events/update with {:formats=>[:html] ...
Because the controller is trying to process it as HTML, not as Javascript. I thought that was what :remote => true was for? If not, what's the point?
So I found I can get around this by explicitly adding :format => :json to my form_for:
<%= form_for event, :format => :json, :remote => true do |f| %>
But can anyone tell me why I have to do that? What am I missing?
Edited by Roger, 13 June 2011 - 02:29 PM.
removed spam link


Sign In
Create Account

Back to top









