F.send in form?

Can you do f.send in a form? I have questions and the data type stored
a db.

<% Question.all.each do |question| %>

<%= f.send(:label, question.name), :class => ‘control-label’

<%= f.send(question.data_type.to_sym, :question, :name) %>

<%= ’ allergic to shellfish?’ %>

    <% end %>

Of course! Are you encountering any problems with that?

Dheeraj K.

Is there something I need to do to the data_type to make it recognize
it as a method?

wrong number of arguments (3 for 0)

48: <%= f.label question.name.to_sym, :class => 'control-label' %> 49:
50: <%= question.data_type "person[person_question_ids][]", question.id, nil %> - <%= ' allergic to shellfish?' %> 51:

On Mon, Jul 30, 2012 at 9:17 PM, Dheeraj K.
[email protected]wrote:

<% Question.all.each do |question| %>

*“In matters of style, swim with the current; in matters of principle,
stand like a rock.”
Thomas Jefferson

On Monday, 30 July 2012 23:25:45 UTC-4, Me wrote:


Wait, what? You posted the correct code in your original post, but this
isn’t that code. Line 50 here is saying, “call the data_type method on
question object with these three parameters”. The generated accessor
doesn’t understand the parameters, and you get the error.

If you want to call a method whose name is selected at runtime, you
to use send.

–Matt J.

Been a while, I had the closing bracket in the wrong spot:
send needs all the params, it was erroring on , if i put the closing
bracket right after the data_type or name
<%= person_question.send(question.data_type.to_sym, question.name,
=> ‘text_field’) %>

You can access the object by using


then you can do


here ‘f.object’ return an instance of Question, but i think that
you are trying to do you are doing it wrong, can you elaborate in what
are trying to do?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs