I guess you are looking for this or probably i misunderstood your question
def show
  @question = Question.find(params[:id])
  @user = @question.user
end


On Fri, Aug 31, 2012 at 8:56 PM, Nate FT <li...@ruby-forum.com> wrote:

> I have a User and a Question model, User has_many questions and Question
> belongs_to user.
>
> On my question show page, I show a question, along with the name of the
> user who's asking the question.
>
> Everything seems to be working fine, but my controller looks like this:
>
> questions_controller.rb
> .
> .
> .
> def show
>   @question = Question.find(params[:id])
>   @user = User.find(@question.user_id)
> end
>
>
> I know rails must have a less messy way to figure out which user the
> question belongs to. I've read that using something like question.user
> would give me what I need, but I can't figure out how to implement it in
> my controller.
>
> Sorry for the simple question, any suggestions are appreciated. Thanks!
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> 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 rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>


-- 
Thanks,
Aash

-- 
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to