Ruby request passing wrong parameter to object -
ok, have basic ruby question can not find reply here. have web app tracks users post advertisements called listings. have index of listing titles across users. each user has many listings.
so in index of listings have next code
<%= link_to listing.title, listing %>
listing goes page contains both user contact info , detailed advertisement. problem when goes page trying pass listing.id user.id instead of passing user_id
listing object.
the controller method showing detailed advertisement next 2 lines.
@user = user.find(params[:id]) @listing = listing.find(params[:id])
the error getting couldn't find user 'id' = 45 when follow link localhost:3000/listings/45
. not have 45 users have more 45 listings. confused on how foreign key pass correctly in case.
i running ruby 2.1.3 rails 4.2.0.beta2
thank help.
you trying find user
, listing
using same id
, while receive id
listing
in listingcontroller
.
assuming have relationships setup in 2 models, way right listing
, user
is:
@listing = listing.find(params[:id]) @user = @listing.user
ruby-on-rails
No comments:
Post a Comment