ruby on rails - How to link_to a show page from another MVC? -


i error when pull http://0.0.0.0:3000/activities:

activerecord::recordnotfound in activitiescontroller#index couldn't find valuation 'id'= line: @valuation = valuation.find(params[:id])

activities_controller

def index   @activities = activity.order("created_at desc").paginate(:page => params[:page])   @valuation = valuation.find(params[:id]) end 

activities/index

<% @activities.each |activity| %>   <%= render "activities/#{activity.trackable_type.underscore}/#{activity.action}", activity: activity %> <% end %> 

activities/valuations/_create

added value   <%= activity.created_at.strftime('%b %d @ %l:%m%p') %>   <%= link_to activity.trackable.name, valuation_path(@valuation) %> #trying fix 

the goal when users looking @ activities feed can click on activity , directed respective valuation's show page, can or comment on it.

routes

resources :activities   resources :valuations end 

please let me know if need further explanation or code me otherwise here's gist of it :)

development.log

    started "/activities" 127.0.0.1 @ 2015-06-03 14:14:49 -0400 processing activitiescontroller#index html   [1m[35muser load (0.2ms)[0m  select  "users".* "users" "users"."id" = ? limit 1  [["id", 1]]   [1m[36mhabit load (0.1ms)[0m  [1mselect "habits".* "habits" "habits"."user_id" = ?[0m  [["user_id", 1]]   [1m[35mactsastaggableon::tag load (0.2ms)[0m  select "tags".* "tags" (lower(name) = lower('ingrain'))   [1m[36mcache (0.0ms)[0m  [1mselect "habits".* "habits" "habits"."user_id" = ?[0m  [["user_id", 1]]   [1m[35m (0.1ms)[0m  select count(*) "habits" "habits"."user_id" = ?  [["user_id", 1]]   [1m[36mvaluation load (0.1ms)[0m  [1mselect  "valuations".* "valuations" "valuations"."id" = ? limit 1[0m  [["id", nil]] completed 404 not found in 11ms  activerecord::recordnotfound (couldn't find valuation 'id'=):   app/controllers/activities_controller.rb:4:in `index'     rendered /users/galli01anthony/.rvm/gems/ruby-2.1.3/gems/actionpack-4.2.0.rc3/lib/action_dispatch/middleware/templates/rescues/_source.erb (9.3ms)   rendered /users/galli01anthony/.rvm/gems/ruby-2.1.3/gems/actionpack-4.2.0.rc3/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (5.2ms)   rendered /users/galli01anthony/.rvm/gems/ruby-2.1.3/gems/actionpack-4.2.0.rc3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.6ms)   rendered /users/galli01anthony/.rvm/gems/ruby-2.1.3/gems/actionpack-4.2.0.rc3/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (126.4ms)   started "/activities" 127.0.0.1 @ 2015-06-03 14:14:50 -0400 processing activitiescontroller#index html   [1m[35muser load (0.2ms)[0m  select  "users".* "users" "users"."id" = ? limit 1  [["id", 1]]   [1m[36mhabit load (0.1ms)[0m  [1mselect "habits".* "habits" "habits"."user_id" = ?[0m  [["user_id", 1]]   [1m[35mactsastaggableon::tag load (0.2ms)[0m  select "tags".* "tags" (lower(name) = lower('ingrain'))   [1m[36mcache (0.0ms)[0m  [1mselect "habits".* "habits" "habits"."user_id" = ?[0m  [["user_id", 1]]   [1m[35m (0.1ms)[0m  select count(*) "habits" "habits"."user_id" = ?  [["user_id", 1]]   [1m[36mvaluation load (0.1ms)[0m  [1mselect  "valuations".* "valuations" "valuations"."id" = ? limit 1[0m  [["id", nil]] completed 404 not found in 8ms  activerecord::recordnotfound (couldn't find valuation 'id'=):   app/controllers/activities_controller.rb:4:in `index'     rendered /users/galli01anthony/.rvm/gems/ruby-2.1.3/gems/actionpack-4.2.0.rc3/lib/action_dispatch/middleware/templates/rescues/_source.erb (9.0ms)   rendered /users/galli01anthony/.rvm/gems/ruby-2.1.3/gems/actionpack-4.2.0.rc3/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (3.6ms)   rendered /users/galli01anthony/.rvm/gems/ruby-2.1.3/gems/actionpack-4.2.0.rc3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.2ms)   rendered /users/galli01anthony/.rvm/gems/ruby-2.1.3/gems/actionpack-4.2.0.rc3/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (35.2ms) 

to link_to show page code understand having need to

  1. resources :activities resources :valuations end
  2. since it's polymorpic use trackable find id , put line: <%= link_to activity.trackable.name, activity_valuation_path(activity, activity.trackable_id) %>
  3. take line out index: @valuation = valuation.find(params[:id])

hopefully helps!


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -