Garnica1999
Garnica1999

Reputation: 215

ArgumentError in select_tag on rails

I'm trying to create a select_tag inside a form in rails, but when impelementar it shows me the following error: wrong number of arguments (given 4, expected 1..3) What I want to do is implement the select with html attributes and the prompt. The method cargarMaterias, searches the database and returns an array of elements, its current impression is as follows:

["1-Sistemas de Informacion", "2-Programacion", "3-Matematicas", "4-Ingenieria Web"]

Oh, I forgot, the selected_tag is implemented as follows:

<%= select_tag :codigo_materia, Subject.cargarMaterias,{ prompt: "Seleccione la materia"}, {id: "EditboxCodigoMatHistMat", class: "EditBox"} %>

I've been doing the same thing for several hours, but I still can not solve this problem. Thank you.

Upvotes: 0

Views: 52

Answers (1)

Pavan
Pavan

Reputation: 33552

select_tag(name, option_tags = nil, options = {}) public

You should rewrite your select_tag as below

<%= select_tag :codigo_materia, Subject.cargarMaterias, { prompt: "Seleccione la materia", id: "EditboxCodigoMatHistMat", class: "EditBox"} %>

Both options and html_options should go as last argument to the select_tag. In other words, any other standard HTML keys also should be passed as options.

Further to simplify, it can be written as just

<%= select_tag :codigo_materia, Subject.cargarMaterias, prompt: "Seleccione la materia", id: "EditboxCodigoMatHistMat", class: "EditBox" %>

Note:

Your value for option_tags is flawed. It should be passed as container to options_for_select like so

<%= select_tag :codigo_materia, options_for_select(Subject.cargarMaterias), prompt: "Seleccione la materia", id: "EditboxCodigoMatHistMat", class: "EditBox" %>

Upvotes: 2

Related Questions