On 8 August 2011 09:55, Sayuj Othayoth <[email protected]> wrote:
> Hi,
>
>
> I've 2 tables
> 1. Users
> 2. StatusMessages
>
> @user = Users.find(1)
> @status = @user.status_messages
>
> with these lines I'm getting the record of users and status_messages table.
> here I can refer in @status with @user.id for status messages of each user.
> in this I want to check this for each user in my code.
>
> is there any way to get the data - username(from Users) and
> status_message(from StatusMessage) in a single variable.
> ie I want to access like:
> @userstatus.username
> @userstatus.status_message

If @status_message is a StatusMessage then you can say
@status_message.user.name
@status_message.message
or whatever the column names are.  This assumes that StatusMessage
belongs_to :user

Does that solve the problem?

If you don't want to use @status_message.user.name but would rather
say @status_message.user_name then define an instance method of
StatusMessage that returns user.name.  In either case don't forget to
check for @status_message.user nil if you can ever have a message
without a user.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to