User can't delete his own account , Rails 4 + Devise - ruby-on-rails

I have Ruby on Rails 4 application also I am using Devise gem to provide login/register.
Everything works just fine, but users that are logged in can't delete their own account. Any other delete functions work, so Javascript shouldn't be a problem.
In view:
<%= link_to "Delete account", registration_path(resource_name), data: { confirm: "Your profile will be permanently deleted. Are you sure?" }, method: :delete%>
I am overriding default devise Registration controller with this:
class RegistrationsController < Devise::RegistrationsController
clear_respond_to
respond_to :json
protected
def update_resource(resource, params)
resource.update_without_password(params)
end
end
My log file:
Started DELETE "/ru/users" for xx.xxx.xxxx.xx at 2015-05-26 22:30:45 +0300
Processing by RegistrationsController#destroy as HTML
Parameters: {"authenticity_token"=>"dXKjMMmKibIy2LNCrR66JuThjPzqsdtjFMXTCubcFe8=", "locale"=>"ru"}
[1m[36mUser Load (0.3ms)[0m [1mSELECT `users`.* FROM `users` WHERE `users`.`id` = 66 ORDER BY `users`.`id` ASC LIMIT 1[0m
[1m[35mCountry Load (0.3ms)[0m SELECT `countries`.* FROM `countries` WHERE `countries`.`id` = 1 LIMIT 1
[1m[36m (0.6ms)[0m [1mSELECT COUNT(*) FROM `girls` WHERE (country_id=1) AND (vip_recomend >= '2015-05-26 22:30:45')[0m
[1m[35m (0.4ms)[0m SELECT COUNT(*) FROM `girls` WHERE (country_id=1) AND (recomend >= '2015-05-26 22:30:45')
[1m[36m (0.3ms)[0m [1mSELECT COUNT(*) FROM `girls` WHERE (country_id=1) AND (highlight >= '2015-05-26 22:30:45')[0m
[1m[35m (0.3ms)[0m SELECT COUNT(*) FROM `girls` WHERE (country_id=1) AND (vip_highlight >= '2015-05-26 22:30:45')
[1m[36mRegion Load (0.2ms)[0m [1mSELECT `regions`.* FROM `regions` WHERE `regions`.`country_id` = 1[0m
[1m[35mList Load (0.3ms)[0m SELECT `lists`.* FROM `lists` WHERE (billing_id =5) ORDER BY `lists`.`id` ASC LIMIT 1
[1m[36m (0.3ms)[0m [1mBEGIN[0m
[1m[35m (0.2ms)[0m COMMIT
[1m[36m (0.2ms)[0m [1mBEGIN[0m
[1m[35m (0.2ms)[0m COMMIT
Redirected to http://xxxxxxxxxxx.xxx.xxx/ru
Completed 302 Found in 24ms (ActiveRecord: 4.4ms)
Description:
When user pushes delete button, user gets message :
translation missing: ru.devise.registrations.user.destroyed
also he is logged out from his account, but the actual destroying never happens. What could be possible problem?
Thanks for your time.
Best wishes.

Here Destroy deletes user account by using destroy method of devise registrations_controller. For translation missing: ru.devise.registrations.user.destroyed you need to make changes in devise.ru.yml file -
ru:
devise:
registrations:
user:
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
This is background process. So, you can't see in your logs(delete sql query).

Related

Nested resource failing to update

I'm trying to do what I think should be simple: do a simple edit on a single text string field with the default update action. But it just doesn't seem to work, despite many attempts and alterations.
There are no errors and the flash message responds successfully, but information isn't saved to the database at all:
routes.rb
resources :interviews do
resources :invitations do
put :accept
end
end
views/invitations/edit.html.haml
= simple_form_for [#interview, #invitation] do |f|
= f.error_notification
= f.input :testing
= f.submit 'Edit Invitstion', :class => 'button small'
controllers/invitations_controller.rb
def update
#invitation = Invitation.find(params[:id])
#interview = Interview.find(params[:interview_id])
#invitation.update_attributes(invitation_params)
if #invitation.update_attributes(invitation_params)
redirect_to edit_interview_invitation_path(#interview, #invitation), notice: "Your profile has been successfully updated."
else
render action: "edit"
end
end
private
def invitation_params
params.permit(:user_id, :interview_id, :invitation_id, :session_time, :workflow_state, :testing)
end
And here's the log:
Started PATCH "/interviews/3/invitations/7" for ::1 at 2016-05-15 19:01:52 +0800
Processing by InvitationsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"o0U5t0yPN0aE2er+DWK0uxqRGyp4ywfdSrEfvwiSQ3UUaOnr3Fd0raFs1IUqVzizKoqxRU0DDpmvysntB9fdhQ==", "invitation"=>{"interview_id"=>"3", "workflow_state"=>"invited", "session_time"=>"", "testing"=>"testtesttest"}, "commit"=>"Edit Invitstion", "interview_id"=>"3", "id"=>"7"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 7]]
Invitation Load (0.2ms) SELECT "invitations".* FROM "invitations" WHERE "invitations"."id" = $1 LIMIT 1 [["id", 7]]
Role Load (0.2ms) SELECT "roles".* FROM "roles" WHERE "roles"."id" = $1 LIMIT 1 [["id", 3]]
Interview Load (0.2ms) SELECT "interviews".* FROM "interviews" WHERE "interviews"."id" = $1 ORDER BY created_at DESC LIMIT 1 [["id", 3]]
CACHE (0.0ms) SELECT "invitations".* FROM "invitations" WHERE "invitations"."id" = $1 LIMIT 1 [["id", "7"]]
CACHE (0.0ms) SELECT "interviews".* FROM "interviews" WHERE "interviews"."id" = $1 ORDER BY created_at DESC LIMIT 1 [["id", "3"]]
Unpermitted parameters: utf8, _method, authenticity_token, invitation, commit, id
(0.1ms) BEGIN
Invitation Exists (0.4ms) SELECT 1 AS one FROM "invitations" WHERE ("invitations"."user_id" = 3 AND "invitations"."id" != 7 AND "invitations"."interview_id" = 3) LIMIT 1
(0.1ms) COMMIT
Redirected to http://localhost:3000/interviews/3/invitations/7/edit
Completed 302 Found in 12ms (ActiveRecord: 1.6ms)
Started GET "/interviews/3/invitations/7/edit" for ::1 at 2016-05-15 19:01:52 +0800
Processing by InvitationsController#edit as HTML
Parameters: {"interview_id"=>"3", "id"=>"7"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 7]]
Invitation Load (0.3ms) SELECT "invitations".* FROM "invitations" WHERE "invitations"."id" = $1 LIMIT 1 [["id", 7]]
Role Load (0.2ms) SELECT "roles".* FROM "roles" WHERE "roles"."id" = $1 LIMIT 1 [["id", 3]]
Interview Load (0.2ms) SELECT "interviews".* FROM "interviews" WHERE "interviews"."id" = $1 ORDER BY created_at DESC LIMIT 1 [["id", 3]]
Rendered invitations/edit.html.haml within layouts/application (6.1ms)
Completed 200 OK in 48ms (Views: 39.1ms | ActiveRecord: 1.6ms)
Check the format of your params object in your logs. Your invitation params are being passed within the params["invitation"] key, yet you're whitelisting and updating your object based on the params in the root params hash.
Also note that your logs are reporting that you're trying to update your invitation with unpermitted params:
Unpermitted parameters: utf8, _method, authenticity_token, invitation, commit, id
You can fix this by simply updating your invitation_params to use params[:invitation] rather than params like so:
def invitation_params
params.require(:invitation).permit(:user_id, :interview_id, :invitation_id, :session_time, :workflow_state, :testing)
end
Also, you might want to consider raising an error if you're trying to update a parameter that's not whitelisted to prevent these sorts of issues in the future.
In your rails config:
config.action_controller.action_on_unpermitted_parameters = :raise

How is Ajax Destroy method for a nested resource is causing its parent resource to be destroyed?

I have resources set up like this:
resources :scoreboards do
resources :teams
end
On my scoreboard#show view page, I have a collection for the team model which generates a div for each team. Beside each team-div is a Delete button which routes to a method in the teams_controller to delete that team.
Here is a list of all the code associated with it:
The Delete Button next to a team
<div>team example</div> <%= link_to "Del", scoreboard_team_path(#scoreboard, team), remote: true, method: :delete, class: "btn btn-primary" %>
The Teams_controller method for the button
def destroy
#scoreboard = Scoreboard.find(params[:scoreboard_id])
#team = #scoreboard.teams.find(params[:id])
#team.destroy
respond_to do |format|
format.html {redirect_to scoreboard_url(#scoreboard)}
format.js
end
end
The destroy.js.erb file
$( "#team_<%=#team.id%>" ).hide();
Now the issue on hand is that whenever I click on a delete button really fast in quick succession(twice or more on one button), all the Ajax delete buttons stop working. This is most likely because the Scoreboard resource the teams were associated to has been deleted because I get the following error in the Scoreboards_Controller:
NoMethodError in ScoreboardsController#show
undefined method `teams' for nil:NilClass
def show
#scoreboard = Scoreboard.find_by_id(params[:id])
#team = #scoreboard.teams.build # new team form on the page
#comment = #scoreboard.comments.new
#schedule = #scoreboard.schedules.build
end
Then when I check my list of Scoreboards, the #Scoreboard resource which the #team was associated to does not exist anymore. Why is that happening?
Edit: Checking the development logs has clarified what is happening.
So I click delete really fast and it destroys the Team associated with that delete button. Since I manage to click the delete button twice before the destroy.js.erb files processes(hides the deleted div), the Teams_Controller#destroy method is run again on the deleted team, however there is nothing to delete, therefore the Teams_Controller#destroy proceeds to redirect to #scoreboard. Now for some reason, the Scoreboards_Controller#destroy executes and deletes the #scoreboard and after that it attempts to redirect again and encounters a routing error because the scoreboard no longer exists.
Here is some of the log for clarification:
Started DELETE "/scoreboards/45/teams/478" for 99.000.000.000 at 2015-12-12 03:54:09 +0000
Processing by TeamsController#destroy as JS
Parameters: {"scoreboard_id"=>"45", "id"=>"478"}
[1m[36mScoreboard Load (0.3ms)[0m [1mSELECT "scoreboards".* FROM "scoreboards" WHERE "scoreboards"."id" = ? ORDER BY "scoreboards"."created_at" DESC LIMIT 1[0m [["id", 45]]
[1m[35mTeam Load (0.2ms)[0m SELECT "teams".* FROM "teams" WHERE "teams"."scoreboard_id" = ? AND "teams"."id" = ? LIMIT 1 [["scoreboard_id", 45], ["id", 478]]
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
[1m[35mSQL (0.4ms)[0m DELETE FROM "teams" WHERE "teams"."id" = ? [["id", 478]]
[1m[36m (10.6ms)[0m [1mcommit transaction[0m
Rendered teams/destroy.js.erb (0.2ms)
Completed 200 OK in 48ms (Views: 28.1ms | ActiveRecord: 11.8ms)
Started DELETE "/scoreboards/45/teams/478" for 99.000.000.000 at 2015-12-12 03:54:09 +0000
Processing by TeamsController#destroy as JS
Parameters: {"scoreboard_id"=>"45", "id"=>"478"}
[1m[35mScoreboard Load (0.3ms)[0m SELECT "scoreboards".* FROM "scoreboards" WHERE "scoreboards"."id" = ? ORDER BY "scoreboards"."created_at" DESC LIMIT 1 [["id", 45]]
[1m[36mTeam Load (0.2ms)[0m [1mSELECT "teams".* FROM "teams" WHERE "teams"."scoreboard_id" = ? AND "teams"."id" = ? LIMIT 1[0m [["scoreboard_id", 45], ["id", 478]]
Redirected to https://score-app-kpauls.c9.io/scoreboards/45
Completed 302 Found in 19ms (ActiveRecord: 0.5ms)
Started DELETE "/scoreboards/45" for 99.000.000.000 at 2015-12-12 03:54:09 +0000
Processing by ScoreboardsController#destroy as JS
Parameters: {"id"=>"45"}
[1m[35mScoreboard Load (0.2ms)[0m SELECT "scoreboards".* FROM "scoreboards" WHERE "scoreboards"."id" = ? ORDER BY "scoreboards"."created_at" DESC LIMIT 1 [["id", 45]]
[1m[36mUser Load (0.1ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1[0m [["id", 105]]
[1m[35mCACHE (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 105]]
[1m[36mCACHE (0.0ms)[0m [1mSELECT "scoreboards".* FROM "scoreboards" WHERE "scoreboards"."id" = ? ORDER BY "scoreboards"."created_at" DESC LIMIT 1[0m [["id", "45"]]
[1m[35m (0.2ms)[0m begin transaction
[1m[36mTeam Load (0.1ms)[0m [1mSELECT "teams".* FROM "teams" WHERE "teams"."scoreboard_id" = ?[0m [["scoreboard_id", 45]]
[1m[35mSQL (0.3ms)[0m DELETE FROM "teams" WHERE "teams"."id" = ? [["id", 479]]
[1m[36mSQL (0.0ms)[0m [1mDELETE FROM "teams" WHERE "teams"."id" = ?[0m [["id", 480]]
[1m[35mSQL (0.1ms)[0m DELETE FROM "teams" WHERE "teams"."id" = ? [["id", 481]]
[1m[36mSQL (0.1ms)[0m [1mDELETE FROM "teams" WHERE "teams"."id" = ?[0m [["id", 482]]
[1m[35mComment Load (0.1ms)[0m SELECT "comments".* FROM "comments" WHERE "comments"."scoreboard_id" = ? [["scoreboard_id", 45]]
[1m[36mSQL (0.1ms)[0m [1mDELETE FROM "scoreboards" WHERE "scoreboards"."id" = ?[0m [["id", 45]]
[1m[35m (14.1ms)[0m commit transaction
Redirected to https://score-app-kpauls.c9.io/scoreboards
Completed 302 Found in 39ms (ActiveRecord: 15.6ms)
After this the program encounters a routing error. I will continue to look into it but if anyone could help find the reason why scoreboards_controller#destroy is being called, it'd be really appreciated.
Update on the Problem:
So I have figured out the problem. I had these two methods in my application_controller file.
rescue_from ActiveRecord::RecordNotFound do
flash[:warning] = 'Resource not found.'
redirect_back_or root_path
end
def redirect_back_or(path)
redirect_to request.referer || path
end
Whenever, I would click on the delete button twice in quick succession, the destroy action would be rerouted to the scoreboard#show page and proceed to call the destroy method for that resource on the second click. This is because the #team which the destroy method was being called for had already been destroyed in the first click therefore requesting a redirect. I did get the flash messages after I refreshed the page to go the home page but dismissed them as relevant at first but they were key to the conclusion.
The code infrastructure looks good, I would recommend looking at the associations and making sure you don't have dependent: :destroy on team belongs_to :scoreboard
--
In regards the problem of multiple "delete" button clicking, the problem looks like you're getting a redirect to the parent resource. I don't have any reason why this would be the case, except that perhaps Rails has an inbuilt set of functionality to load "parent" routes if the child fails.
The way I would tackle the fix is to use conditions:
def destroy
#scoreboard = Scoreboard.find(params[:scoreboard_id])
#team = #scoreboard.teams.find params[:id]
if #team.destroy
respond_to do |format|
format.html {redirect_to scoreboard_url(#scoreboard)} #-> could this be the reason for the redirect?????
format.js
end
else
redirect_to scoreboard_teams_path(#scoreboard), notice: "Team Already Deleted"
end
end
I'd also look at conditioning the #team -- if #team && #team.destroy - I can refactor if you wanted more information.
Doing this will give you a definite flow which can handle exceptions. I think the problem is that when you click the delete button (and the record no longer exists), Rails is unable to handle the exception.
The inbuilt way that Rails comes back with errors is to redirect to the object_path(#object), and show the errors (like you've got in your format.html).
Therefore, I would guess that Rails is trying to take you back to #scoreboard (scoreboard_path(#scoreboard)), and since you have method: :delete, it's running the destroy method for that controller.
To fix it, you'd need to use the conditions above to let Rails know what to do in case of problems.
In your teams_controller in the destroy action, I suggest you change this line:
#team = #scoreboard.teams.find(params[:id])
for
#team = Team.find(params[:id])

Updating an attribute in Rails controller

I'm trying to update the shop_id of a user when they click an add button.
The controller method called is this:
def update_shop
#user = User.find(params[:id])
#shop = Shop.find(params[:shop_id])
#user.update_attribute(:shop_id, params[:shop_id])
flash[:success] = "Added Shop!"
redirect_to #shop
end
The server when the button is clicked reads:
Started POST "/updateshop?id=3&shop_id=1" for ::1 at 2015-08-31 05:50:52 -0500
Processing by UsersController#update_shop as HTML
Parameters: {"authenticity_token"=>"jRozldw1u3TrWhaL6CeJyw4Tm5V5S/IFEQQulRkuV1Ot85kmPOsMa2jH2L6m8EFDpy7Ygc9SMBvPLJCuosHXUg==", "id"=>"3", "shop_id"=>"1"}
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 3]]
Shop Load (0.1ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = ? LIMIT 1 [["id", 1]]
(0.1ms) begin transaction
SQL (0.3ms) UPDATE "users" SET "shop_id" = ?, "updated_at" = ? WHERE "users"."id" = ? [["shop_id", 1], ["updated_at", "2015-08-31 10:50:52.089826"], ["id", 3]]
(5.8ms) commit transaction
But it doesn't actually update User.shop_id
And sometimes it doesn't have the update line, and reads:
Started POST "/updateshop?id=3&shop_id=1" for ::1 at 2015-08-31 05:56:54 -0500
Processing by UsersController#update_shop as HTML
Parameters: {"authenticity_token"=>"D1ODlfDnhJmQ9NUfh+GL2JE747nJC2t4eqOziRGNCaUvuikmEDkzhhNpGyrJNkNQOAagrX8SqWakiw2yqmKJpA==", "id"=>"3", "shop_id"=>"1"}
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 3]]
Shop Load (0.1ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = ? LIMIT 1 [["id", 1]]
(0.1ms) begin transaction
(0.1ms) commit transaction
The parameters are passed correctly and I think update_attribute is correct, what's going wrong?
The value is already assigned, this is why it's not updated. I mean, there is no actual changes, this is why no UPDATE statements were issued.

Cannot update status of table specific instance because rollback is taking place

I have a table subscription with a column status. In my subscriptions controller I have a method accept_player that is supposed to update the subscription.status to "confirmed!"
def accept_player
#subscription = Subscription.find(params[:subscription_id_accept_player])
#subscription.status = "confirmed!"
#subscription.save
authorize #subscription
redirect_to tournament_subscriptions_path(#subscription.tournament)
end
unfortunately every time I try to trigger that method, a rollback seem to take place:
Started POST "/accept_player/39" for ::1 at 2015-07-08 22:01:21 +0100
ActiveRecord::SchemaMigration Load (12.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
/Users/davidgeismar/code/davidgeismar/tennis-match/app/controllers/subscriptions_controller.rb:141: warning: duplicated key at line 155 ignored: "CardType"
Processing by SubscriptionsController#accept_player as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"aas8OPHBpvPwNbbmx/SVipsRM+eKo63nuVilMroxKcU9HRVonjSqEuH7aLY91gFi9PHMUsUqRqk7qhnv2m4L/A==", "subscription_id_accept_player"=>"39", "commit"=>"Confirmer ce Joueur", "subscription_id"=>"39"}
User Load (13.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 2]]
Subscription Load (11.6ms) SELECT "subscriptions".* FROM "subscriptions" WHERE "subscriptions"."id" = $1 LIMIT 1 [["id", 39]]
(5.7ms) BEGIN
Subscription Exists (0.8ms) SELECT 1 AS one FROM "subscriptions" WHERE ("subscriptions"."user_id" = 20 AND "subscriptions"."id" != 39 AND "subscriptions"."tournament_id" = 9) LIMIT 1
(12.6ms) ROLLBACK
Tournament Load (2.4ms) SELECT "tournaments".* FROM "tournaments" WHERE "tournaments"."id" = $1 LIMIT 1 [["id", 9]]
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 2]]
Redirected to http://localhost:3000/tournaments/9/subscriptions
Completed 302 Found in 246ms (ActiveRecord: 79.7ms)
Any ideas about what might be going wrong here ?
This code:
authorize #subscription
is probably causing the rollback. If you're in dev mode, just comment it out, reload!, and try to manually add a record and see if that's the cause.

How to link_to a show page from another MVC?

I get this error when I pull up http://0.0.0.0:3000/activities:
ActiveRecord::RecordNotFound in ActivitiesController#index Couldn't
find Valuation with '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 do |activity| %>
<%= render "activities/#{activity.trackable_type.underscore}/#{activity.action}", activity: activity %>
<% end %>
activities/valuations/_create
added value
<%= activity.created_at.strftime('%B %d at %l:%M%P') %>
<%= link_to activity.trackable.name, valuation_path(#valuation) %> #Trying to Fix This
The goal is so that when users are looking at the activities feed they can click on a activity and be directed to that respective valuation's show page, which is where they can like or comment on it.
routes
resources :activities do
resources :valuations
end
Please let me know if you need any further explanation or code to help you help me otherwise here's the gist of it :)
development.log
Started GET "/activities" for 127.0.0.1 at 2015-06-03 14:14:49 -0400
Processing by ActivitiesController#index as HTML
[1m[35mUser Load (0.2ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
[1m[36mHabit Load (0.1ms)[0m [1mSELECT "habits".* FROM "habits" WHERE "habits"."user_id" = ?[0m [["user_id", 1]]
[1m[35mActsAsTaggableOn::Tag Load (0.2ms)[0m SELECT "tags".* FROM "tags" WHERE (LOWER(name) = LOWER('ingrain'))
[1m[36mCACHE (0.0ms)[0m [1mSELECT "habits".* FROM "habits" WHERE "habits"."user_id" = ?[0m [["user_id", 1]]
[1m[35m (0.1ms)[0m SELECT COUNT(*) FROM "habits" WHERE "habits"."user_id" = ? [["user_id", 1]]
[1m[36mValuation Load (0.1ms)[0m [1mSELECT "valuations".* FROM "valuations" WHERE "valuations"."id" = ? LIMIT 1[0m [["id", nil]]
Completed 404 Not Found in 11ms
ActiveRecord::RecordNotFound (Couldn't find Valuation with '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 GET "/activities" for 127.0.0.1 at 2015-06-03 14:14:50 -0400
Processing by ActivitiesController#index as HTML
[1m[35mUser Load (0.2ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
[1m[36mHabit Load (0.1ms)[0m [1mSELECT "habits".* FROM "habits" WHERE "habits"."user_id" = ?[0m [["user_id", 1]]
[1m[35mActsAsTaggableOn::Tag Load (0.2ms)[0m SELECT "tags".* FROM "tags" WHERE (LOWER(name) = LOWER('ingrain'))
[1m[36mCACHE (0.0ms)[0m [1mSELECT "habits".* FROM "habits" WHERE "habits"."user_id" = ?[0m [["user_id", 1]]
[1m[35m (0.1ms)[0m SELECT COUNT(*) FROM "habits" WHERE "habits"."user_id" = ? [["user_id", 1]]
[1m[36mValuation Load (0.1ms)[0m [1mSELECT "valuations".* FROM "valuations" WHERE "valuations"."id" = ? LIMIT 1[0m [["id", nil]]
Completed 404 Not Found in 8ms
ActiveRecord::RecordNotFound (Couldn't find Valuation with '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 your show page with the code I understand you having you need to
resources :activities do
resources :valuations
end
Since it's polymorpic use trackable to find the id and put the line: <%= link_to activity.trackable.name, activity_valuation_path(activity, activity.trackable_id) %>
Take this line out from your index: #valuation = Valuation.find(params[:id])
Hopefully that helps!
you got nested resources:
resources :activities do
resources :valuations
end
this does not create the method
valuation_path()
it creates
activities_valuation_path()
if you want to create the valuation path you need to refactor to:
resources :activities do
resources :valuations
end
resources :valuations # this will create your method
or if the valuation is strongly connected to an activity i recommend using
activities_valuation_path(:activity_id, :valuation_id)

Resources