sid
sid

Reputation: 11

radio_button in edit form

I have a standard scaffold. In my edit action it looks like the value set with the radio button on the create action is not shown. How do I get the form to fill in the set value?

<%= form_for([@rating]) do |f| %>

<%= f.radio_button :environment, 1 %>
<%= f.radio_button :environment, 2 %>
<%= f.radio_button :environment, 3 %>

Upvotes: 1

Views: 974

Answers (1)

sid
sid

Reputation: 11

Maybe the ruby gurus will frown upon this, but I got something to work here.

Controller:

 def edit  
  @rating = Rating.find(params[:id])

  @a,@b,@c = false
   if @rating.environment == 1
  @a = true
   elsif @rating.environment == 2
  @b = true
   elsif @rating.environment == 3
  @c = true
  end
 end



1<%= f.radio_button :environment, 1, :checked => @a %>
2<%= f.radio_button :environment, 2, :checked => @b %>
3<%= f.radio_button :environment, 3, :checked => @c %>

Upvotes: 1

Related Questions