I have a consistency issue using link_to_remote in rails.
I have 2 use cases for link_to_remote and they generate different ajax. I canβt understand why, and it drives me crazy.
Here is an example use one ...
<%= link_to_remote "section-", :update => "sections", :url => {:action => :destroy, :controller => "sections", :id => @section.id } %>
This creates the appropriate ajax (as shown below) and works as I expect. Note that it raises the: action parameter from the call and correctly inserts it into ajax.
<a href="#" onclick="if { new Ajax.Updater('sections', '/sections/destroy/1', {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('f5e50e62fafd118e4588b33c9571ea6eef864176')}); }; return false;">section-</a>
I also have another instance where I use link_to_remote, but it generates the wrong ajax. The use case is almost identical, except that the controller is different. In any case, I would not expect this to lead to different ajax.
Call...
<%= link_to_remote "question-", :update =>"questions-1", :url => {:action => :destroy, :controller => "questions", :id => @question.id} %>
The resulting ajax ...
<a href="#" onclick="if { new Ajax.Updater('questions-1', '/questions/1', {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('f5e50e62fafd118e4588b33c9571ea6eef864176')}); }; return false;">question-</a>
The obvious difference here is in the second argument of Ajax.Updater. The: action parameter is missing from this path. What for? This leads to a broken code for me, but I cannot understand why this is happening. The calls to link_to_remote are almost identical.
Please point me in the right direction. Thanks.
Below is my route.rb file ...
ActionController::Routing::Routes.draw do |map| map.resources :questions, :has_one => :section, :collection => { :sort => :post } map.resources :sections, :has_many => :questions, :has_one => :form, :collection => { :sort => :post } map.resources :forms, :has_many => :sections