assigning a method argument to a model attribute

Hi,

when i do this:

<%= method(x) %>

in the view

and the method: is

def method(x)

model.x

end

rails give the error of no argument. how do i assign an argument to
the model?

You can do it like this

   model.send(x)

Nevertheless, you normally write

   <%=h @model.x %>

in the view, or prepare some @x in the controller that holds model.x,
depending on how important is @model to the view. Do you really need
that level of indirection?

Hi,

when i do this:

<%= method(x) %>

in the view

and the method: is

def method(x)

model.x

end

First off there's an internal ruby method called "method" so it's best
to avoid that. Aside from that your method should be in the
appropriate view helper file.

Having done all that it's still not going to work:
- in side your method, model isn't defined
- assuming x contains a string and you want to call that method you
can't do it like that (what you've got will try and call the method
called x). you need to use the send method (for example
[1,2,3].send('length') returns 3

Fred

Thanks guys it works now.