Note that there are some explanatory texts on larger screens.

plurals
  1. POSubmit Not Triggering Appropriate Accept Headers Using form_remote_tag
    primarykey
    data
    text
    <p>The <code>form_remote_tag</code> seems to generate the correct html, but format.html is rendered instead of format.js. The two most common answers to format.html being rendered instead of format.js are renaming the file <code>*</code>.rjs to <code>*</code>.js.rjs and making sure the the javascript files are actually loaded. Both of these have been done. Let me know if there's any other information I can provide.</p> <p>[edit] create.js.rjs has been added below. [/edit]</p> <p>Rails 2.3.2</p> <h2>view/projects/show.html.erb</h2> <pre><code>&lt;%= form_remote_tag :url =&gt; { :controller =&gt; :milestones, :action =&gt; :create } #:update =&gt; 'milestone-list', #:url =&gt; { :controller =&gt; "milestones", :action =&gt; :ajax_create}, #:position =&gt; 'bottom' %&gt; &lt;%= render :partial =&gt; 'milestones/form' %&gt; &lt;input type="hidden" id="milestone_project_id" name="milestone[project_id]" value="&lt;%=@project.id %&gt;" /&gt; &lt;%= submit_tag 'Add Milestone' %&gt; </code></pre> <h2>milestones_controller.rb</h2> <pre><code>def create @milestone = Milestone.new(params[:milestone]) respond_to do |format| if @milestone.save flash[:notice] = 'Milestone was successfully created.' format.js {render :layout =&gt; false } format.html { render :show }#redirect_to(@milestone) } format.xml { render :xml =&gt; @milestone, :status =&gt; :created, :location =&gt; @milestone } else format.html { render :action =&gt; "new" } format.xml { render :xml =&gt; @milestone.errors, :status =&gt; :unprocessable_entity } end end end </code></pre> <h2>headers</h2> <p>(domain names and ips have been changed. The server is mongrel with apache setup as proxy)</p> <pre><code>* ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 * HOST: 127.0.0.1:8004 * X_FORWARDED_HOST: slate.project.mydevserver.com * VIA: 1.1 project.mydevserver.com * USER_AGENT: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 * ACCEPT_LANGUAGE: en-us,en;q=0.5 * REFERER: http://slate.project.mydevserver.com/projects/2 * VERSION: HTTP/1.1 * X_FORWARDED_SERVER: project.mydevserver.com * X_FORWARDED_FOR: 1.2.3.4 * ACCEPT_CHARSET: ISO-8859-1,utf-8;q=0.7,*;q=0.7 * CONNECTION: Keep-Alive * ACCEPT_ENCODING: gzip,deflate </code></pre> <h2>generated html</h2> <pre><code>&lt;form action="/milestones" method="post" onsubmit="new Ajax.Request('/milestones', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;"&gt; &lt;div style="margin:0;padding:0"&gt;&lt;input name="authenticity_token" type="hidden" value="wTS9QPqFiGvP3RVlvKsA49Z6xtEGH9gmcLP//XC0whc=" /&gt;&lt;/div&gt; Title: &lt;input id="milestone_title" name="milestone[title]" size="30" type="text" /&gt;&lt;br /&gt; Description: &lt;input id="milestone_description" name="milestone[description]" size="30" type="text" /&gt;&lt;br /&gt; Days: &lt;input id="milestone_days" name="milestone[days]" size="30" type="text" /&gt;&lt;br /&gt; &lt;input type="hidden" id="milestone_project_id" name="milestone[project_id]" value="2" /&gt; &lt;input name="commit" type="submit" value="Add Milestone" /&gt; &lt;/form&gt; </code></pre> <h2>create.js.rjs</h2> <pre><code>page.insert_html :bottom, 'milestone_list', "Hi" </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload