Note that there are some explanatory texts on larger screens.

plurals
  1. POSaving radio buttons values in rails
    text
    copied!<p>I'm trying to use radio buttons in my rails application. Currently the buttons are showing up on the page as expected, but the value is not being saved upon submission. I think the problem is actually with my submit button - nothing is happening when it is pressed.</p> <p>Here is the code for my page with the radio buttons: </p> <pre><code>&lt;div class="form_row&gt; &lt;%= form_for @term, :url=&gt;{ :action =&gt;"update_status" } do |f| %&gt; &lt;%= f.radio_button :status, 'on' %&gt;&lt;b&gt;On&lt;/b&gt; &lt;br/&gt; &lt;%= f.radio_button :status, 'off' %&gt;&lt;b&gt;Off&lt;/b&gt; &lt;br/&gt; &lt;%= f.radio_button :status, 'leave' %&gt;&lt;b&gt;Leave&lt;/b&gt; &lt;br/&gt; &lt;div class="actions"&gt; &lt;%= f.submit "Change term status" %&gt; &lt;/div&gt; &lt;% end %&gt; &lt;/div&gt; </code></pre> <p>I corrected my typo (':actions<code>to</code>:action`) but it's still not working. Here's some more information...</p> <p>The radio buttons are on the top of the page, and the rest of the form is below them. I have two different submit buttons, one for the radio buttons, and one for the fill in the blank information at the bottom of the page. The second form works perfectly, but when I click the "Change term status button" (the button that is supposed to submit the radio buttons by calling <code>update_status</code>, nothing happens.</p> <p>Here is all of the code for my page view:</p> <pre><code>&lt;h1&gt; &lt;%= @title %&gt; &lt;/h1&gt; &lt;div class="form_row&gt; &lt;%= form_for @term, :url=&gt;{ :action =&gt;"update_status" } do |f| %&gt; &lt;%= f.radio_button :status, 'on' %&gt;&lt;b&gt;On&lt;/b&gt; &lt;br/&gt; &lt;%= f.radio_button :status, 'off' %&gt;&lt;b&gt;Off&lt;/b&gt; &lt;br/&gt; &lt;%= f.radio_button :status, 'leave' %&gt;&lt;b&gt;Leave&lt;/b&gt; &lt;br/&gt; &lt;div class="actions"&gt; &lt;%= f.submit "Change term status" %&gt; &lt;/div&gt; &lt;% end %&gt; &lt;/div&gt; &lt;%= form_for @term, :url=&gt;{ :action=&gt;"update" } do |f| %&gt; &lt;div class="field"&gt; &lt;%= f.label :course1, "Course 1" %&gt;&lt;br /&gt; &lt;%= f.text_field :course1 %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :course2, "Course 2" %&gt;&lt;br /&gt; &lt;%= f.text_field :course2 %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :course3, "Course 3" %&gt;&lt;br /&gt; &lt;%= f.text_field :course3 %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :course4, "Course 4" %&gt;&lt;br /&gt; &lt;%= f.text_field :course4 %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit "Update" %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>And here are both definitions: </p> <pre><code> def update @term = Term.find(params[:id]) @dplan=@term.dplan if @term.update_attributes(params[:term]) flash[:success] = "Edit successful." redirect_to @dplan else flash[:success] = "Error" redirect_to @dplan end end def update_status @term = Term.find(params[:id]) @dplan=@term.dplan if @term.update_attributes(params[:term]) flash[:success] = "Term status changed." redirect_to @term else flash[:success] = "Error" redirect_to @term end end </code></pre> <p>Thank you!</p>
 

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