Reputation: 3475
I've come from Django and was wondering how do I specify the default value of model if referenced just by calling it. Ie. <= @user %>
In Django, we can use in the model class;
def __unicode__(self):
return self.fieldname
And it will use whatever field name or combined string we specify. Is this possible in rails?
Cheers, Ben
Upvotes: 0
Views: 90
Reputation: 124459
You probably want to define to_s
in your model:
def to_s
fieldname
end
Then in a view, you can do <%= @user %>
and it'll output the fieldname
you specify above.
Upvotes: 3