I have two loose models - stages and users. (My milestones are actually owned by companies, and companies have many stages.)
Each milestone has a user who is responsible for this - in my stage form, I use the following to find and select users:
<%= f.input :milestone_user, :as => :select, :collection => User.find(:all, :order => "name ASC") %>
This gives me user_id, which I converted in one view to a name as follows:
<%= User.find(milestone.milestone_user).name %>
This works fine, but I want to use it in several views now and donβt like having a query in my views.
I tried moving it to my User model, but I don't know how to do it. I tried this in the model:
scope :username, lambda { where("id = milestone_user")}
And this is in my opinion:
<%= User.username.first_name %>
But he complains about the undefined method for first_name ..
Thanks in advance
Jenny blunt
source share