0

I would like to read the selected value of radiobuttons on my Form.Now null value saved in my DB. Here is my radio buttons:

        <%= w.label :Artikel ,'der' %><%= w.radio_button :Artikel %>
        <%= w.label :Artikel ,'die' %><%= w.radio_button :Artikel %>
        <%= w.label :Artikel ,'das' %><%= w.radio_button :Artikel %>

and this is my Controlle:

def create
    @word=Word.create(params[:word])
    if @word.save
      redirect_to :action => 'index'
    else
      render :action => 'new'
    end
  end

Thank you for your helps

2 Answers 2

1

You need to give each of your radio_button items a second parameter with the value to use:

<%= w.radio_button :Artikel, "der" %>
<%= w.radio_button :Artikel, "die" %>
<%= w.radio_button :Artikel, "das" %>

Then, params[:word][:Artikel] will contain whichever one is selected.

Sign up to request clarification or add additional context in comments.

Comments

1

The view should have been

<%= w.label :Artikel ,'der' %><%= w.radio_button 'artikel', 'der' %>
<%= w.label :Artikel ,'die' %><%= w.radio_button 'artikel', 'die' %>
<%= w.label :Artikel ,'das' %><%= w.radio_button 'artikel', 'das' %>

I assume an attribute called artikel exists in the Word model.

2 Comments

Since he's probably using something like form_for @word do |w|, you don't need the 'word' parameters.
oh yes.. you are right.. i confused it with radio_button_tag. will update the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.