ruby on rails - Simple form radio button -


I am using simple_form gem and in fact it is like simplicity though try to set a simple radio button I have to do this because I get the following error

"undefined local variable or method 'vegetarian'"

1. Even with me How far is

  & lt;% = f.collection_radio_buttons: diet type, [[vegetarian, 'vegetarian'], [vegetarian, 'vegetarian']]% & gt;  

2. Code used before simple_form with an update / patch method, which users need to update and save

  & Lt;% = f. Label (: DietPropay, "Wagon")% & gt; & Lt;% = f.radio_button (: Diet Type, "Vegetarian")% & gt; & Lt;% = f.label (: Diet, "Vegan")% & gt; & Lt;% = f.radio_button (: Diet Type, "Vegetarian")% & gt;  

3. And here's what I am trying to reproduce

   

Note - There are vegetarian and veg select options which will be stored in the database column of DataType.

In your administrator action , add this line

  def actionname @types = ModelName.select (: diettype) .distinct .. end  

Where,

actionname The action that is giving your idea

ModelName is the name of your model in which there is a diettype field.

in view

   With  

   & lt;% = f.collection_radio_buttons: IT Type, @ type, IT type: IT type% & gt;  

Edit:

  & lt;% = f.collection_radio_buttons: IT Type, @ Type: IT Type, : IT Type% & gt; ;  

The above line means:

Create a collection of radio buttons, where

1 : diettype : Variable when you select a radio button

@ type : passing this archive

2 : diettype : Value

EDIT2

As you have specified that you Stable storage is required and you are not taking any value from the database:

Just add the following line, add the controller to There is no need to add:

  & lt;% = f.collection_radio_buttons: name, [['vegetarian', 'vegetarian'], [vegetarian] 'vegetarian']],: first ,: Last% & gt;  

Comments