Colin Law wrote in post #1180547:
> On 12 January 2016 at 08:42, Alex Marie <lists@ruby-forum.com> wrote:
>>
>> 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
You're amazing Colin! It worked perfectly!
You just made my day!!!! I can't thank you enough
--
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/1697a3f98b10e6798b3fe1a225a3f73f%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment