HappyHacking
HappyHacking

Reputation: 868

rails select field custom attribute

I currently have a scaffold with the default new, edit, create, etc. methods.

My new method looks like:

 def new
   @group = params[:id]
   @people = Person.all

Now i want to create a method "select" like

def select
    render action: 'select'
end

and the select.html.erb should only contain one select box to select the group, which I need as input for the new method.

How does a (form?) like this have to look like.

Upvotes: 0

Views: 156

Answers (1)

Joe Half Face
Joe Half Face

Reputation: 2333

First of all

def select
    render action: 'select'
end

For sure won't do anything and probably cause an infinite loop error, because render :action=>your_action renders action of controller, and here you render this action itself.

To interact with views, you need method

respont_to do |format|
format.html
end

As I understood, you need to use radio button. From API:

<%= radio_button_tag(:age, "child") %>
<%= label_tag(:age_child, "I am younger than 21") %>
<%= radio_button_tag(:age, "adult") %>
<%= label_tag(:age_adult, "I'm over 21") %>

Upvotes: 1

Related Questions