Ruby on Rails Tuesday, January 12, 2016

On 12 January 2016 at 08:42, Alex Marie <lists@ruby-forum.com> wrote:
> Hey there,
>
> I'm super new to RoR. I've been working on an eCommerce project for
> practice. Currently my website has buyers and sellers. Each seller has
> personal page.
>
> I'm trying to figure out how to show each seller's listings on their
> personal page. I don't know what to put in my controller
>
> Here's what I got so far:
>
> def shop
> @listings = Listing.where(seller: User.find(params[:id,]))
> @user = User.find(params[:id])
> end

Better to use
@user = User.find(params[:id])
@listings = @user.listings

That probably won't work for you at the moment as you may not have set
up the associations properly. Also, assuming the user has to logon
then you should not be passing the id in the params but should be
saving it in the session when the user logs on, in which case you
would use
@user = current_user

I suggest that you work right through a good tutorial such as
railstutorial.org (which is free to use online) which will show you
the basics of rails. Also study the Rails Guide on ActiveRecord
Associations (and the other Rails Guides).

Colin

>
>
>
> I hope that I'm making sense.
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ec88a5afaf60d0a3ed6a0fe654eb640d%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvpkXswnFXCPTYte0vj7_ZPVjn3s_yYpvKdDCQAT9ZqgQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment