8

I am doing michael hartl's tutorial for ruby on rails and everything works fine locally but not on heroku when the app deploys.. this problem dint arise before chapter 7 of this book: http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#top

are there any details you need to debug this problem? please let me know.....

here are the heroku logs:

$ 2012-07-18T06:10:26+00:00 app[web.1]:     6:         <ul class="nav pull-right">

2012-07-18T06:10:26+00:00 app[web.1]: ActionView::Template::Error (undefined met
hod `find_by_remember_token' for #<Class:0x00000004960740>):
2012-07-18T06:10:26+00:00 app[web.1]:     7:           <li><%= link_to "Home", r
oot_path %></li>
2012-07-18T06:10:26+00:00 app[web.1]:     8:           <li><%= link_to "Help", h
elp_path %></li>
2012-07-18T06:10:26+00:00 app[web.1]:     9:           <% if signed_in? %>
2012-07-18T06:10:26+00:00 app[web.1]:     10:             <li><%= link_to "Users
", users_path %></li>
2012-07-18T06:10:26+00:00 app[web.1]:     11:             <li id="fat-menu" clas
s="dropdown">
2012-07-18T06:10:26+00:00 app[web.1]:     12:               <a href="#" class="d
ropdown-toggle" data-toggle="dropdown">
2012-07-18T06:10:26+00:00 app[web.1]:   app/helpers/sessions_helper.rb:10:in `cu
rrent_user'
2012-07-18T06:10:26+00:00 app[web.1]:   app/helpers/sessions_helper.rb:23:in `si
gned_in?'
2012-07-18T06:10:26+00:00 app[web.1]:   app/views/layouts/application.html.erb:1
1:in `_app_views_layouts_application_html_erb___2533055855927805914_43132200'
2012-07-18T06:10:26+00:00 app[web.1]:   app/views/layouts/_header.html.erb:9:in
`_app_views_layouts__header_html_erb__2547305690965663969_41244280'
2012-07-18T06:10:26+00:00 app[web.1]:
2012-07-18T06:10:26+00:00 app[web.1]:
2012-07-18T06:10:26+00:00 heroku[router]: GET whizcollab.herokuapp.com/ dyno=web
.1 queue=0 wait=0ms service=345ms status=500 bytes=643
2012-07-18T06:10:34+00:00 app[web.1]:
2012-07-18T06:10:34+00:00 app[web.1]: Started GET "/" for 115.87.214.246 at 2012
-07-18 06:10:34 +0000
2012-07-18T06:10:34+00:00 app[web.1]:
2012-07-18T06:10:34+00:00 app[web.1]: Processing by StaticPagesController#home a
s HTML
2012-07-18T06:10:34+00:00 app[web.1]:   Rendered static_pages/home.html.erb with
in layouts/application (0.6ms)
2012-07-18T06:10:34+00:00 app[web.1]:   Rendered layouts/_shim.html.erb (0.0ms)
2012-07-18T06:10:34+00:00 app[web.1]:   Rendered layouts/_header.html.erb (1.2ms
)
2012-07-18T06:10:34+00:00 app[web.1]: Completed 500 Internal Server Error in 4ms

2012-07-18T06:10:34+00:00 app[web.1]: ActionView::Template::Error (undefined met
hod `find_by_remember_token' for #<Class:0x00000004960740>):
2012-07-18T06:10:34+00:00 app[web.1]:
2012-07-18T06:10:34+00:00 app[web.1]:     8:           <li><%= link_to "Help", h
elp_path %></li>
2012-07-18T06:10:34+00:00 app[web.1]:     9:           <% if signed_in? %>
2012-07-18T06:10:34+00:00 app[web.1]:     6:         <ul class="nav pull-right">

2012-07-18T06:10:34+00:00 app[web.1]:     10:             <li><%= link_to "Users
", users_path %></li>
2012-07-18T06:10:34+00:00 app[web.1]:     7:           <li><%= link_to "Home", r
oot_path %></li>
2012-07-18T06:10:34+00:00 app[web.1]:     11:             <li id="fat-menu" clas
s="dropdown">
2012-07-18T06:10:34+00:00 app[web.1]:     12:               <a href="#" class="d
ropdown-toggle" data-toggle="dropdown">
2012-07-18T06:10:34+00:00 app[web.1]:   app/helpers/sessions_helper.rb:10:in `cu
rrent_user'
2012-07-18T06:10:34+00:00 app[web.1]:   app/views/layouts/_header.html.erb:9:in
`_app_views_layouts__header_html_erb__2547305690965663969_41244280'
2012-07-18T06:10:34+00:00 app[web.1]:   app/helpers/sessions_helper.rb:23:in `si
gned_in?'
2012-07-18T06:10:34+00:00 app[web.1]:   app/views/layouts/application.html.erb:1
1:in `_app_views_layouts_application_html_erb___2533055855927805914_43132200'
2012-07-18T06:10:34+00:00 app[web.1]:
2012-07-18T06:10:34+00:00 app[web.1]:
2012-07-18T06:10:34+00:00 heroku[router]: GET whizcollab.herokuapp.com/ dyno=web
.1 queue=0 wait=0ms service=22ms status=500 bytes=643
2012-07-18T06:12:03+00:00 app[web.1]:
2012-07-18T06:12:03+00:00 app[web.1]:
2012-07-18T06:12:03+00:00 app[web.1]: Started GET "/" for 115.87.214.246 at 2012
-07-18 06:12:03 +0000
2012-07-18T06:12:03+00:00 app[web.1]: Processing by StaticPagesController#home a
s HTML
2012-07-18T06:12:03+00:00 app[web.1]:   Rendered static_pages/home.html.erb with
in layouts/application (0.7ms)
2012-07-18T06:12:03+00:00 app[web.1]:   Rendered layouts/_shim.html.erb (0.0ms)
2012-07-18T06:12:03+00:00 app[web.1]: Completed 500 Internal Server Error in 6ms

2012-07-18T06:12:03+00:00 app[web.1]:   Rendered layouts/_header.html.erb (2.3ms
)
2012-07-18T06:12:03+00:00 app[web.1]: ActionView::Template::Error (undefined met
hod `find_by_remember_token' for #<Class:0x00000004960740>):
2012-07-18T06:12:03+00:00 app[web.1]:
2012-07-18T06:12:03+00:00 app[web.1]:     6:         <ul class="nav pull-right">

2012-07-18T06:12:03+00:00 app[web.1]:     7:           <li><%= link_to "Home", r
oot_path %></li>
2012-07-18T06:12:03+00:00 app[web.1]:     8:           <li><%= link_to "Help", h
elp_path %></li>
2012-07-18T06:12:03+00:00 app[web.1]:     9:           <% if signed_in? %>
2012-07-18T06:12:03+00:00 app[web.1]:     11:             <li id="fat-menu" clas
s="dropdown">
2012-07-18T06:12:03+00:00 app[web.1]:     10:             <li><%= link_to "Users
", users_path %></li>
2012-07-18T06:12:03+00:00 app[web.1]:     12:               <a href="#" class="d
ropdown-toggle" data-toggle="dropdown">
2012-07-18T06:12:03+00:00 app[web.1]:   app/helpers/sessions_helper.rb:10:in `cu
rrent_user'
2012-07-18T06:12:03+00:00 app[web.1]:   app/helpers/sessions_helper.rb:23:in `si
gned_in?'
2012-07-18T06:12:03+00:00 app[web.1]:   app/views/layouts/_header.html.erb:9:in
`_app_views_layouts__header_html_erb__2547305690965663969_41244280'
2012-07-18T06:12:03+00:00 app[web.1]:   app/views/layouts/application.html.erb:1
1:in `_app_views_layouts_application_html_erb___2533055855927805914_43132200'
2012-07-18T06:12:03+00:00 app[web.1]:
2012-07-18T06:12:03+00:00 app[web.1]:
2012-07-18T06:12:03+00:00 heroku[router]: GET whizcollab.herokuapp.com/ dyno=web
.1 queue=0 wait=0ms service=17ms status=500 bytes=643
2012-07-18T06:13:31+00:00 app[web.1]:
2012-07-18T06:13:31+00:00 app[web.1]:
2012-07-18T06:13:31+00:00 app[web.1]: Started GET "/" for 115.87.214.246 at 2012
-07-18 06:13:31 +0000
2012-07-18T06:13:31+00:00 app[web.1]: Processing by StaticPagesController#home a
s HTML
2012-07-18T06:13:31+00:00 app[web.1]:   Rendered static_pages/home.html.erb with
in layouts/application (0.4ms)
2012-07-18T06:13:31+00:00 app[web.1]:   Rendered layouts/_shim.html.erb (0.0ms)
2012-07-18T06:13:31+00:00 app[web.1]:   Rendered layouts/_header.html.erb (1.9ms
)
2012-07-18T06:13:31+00:00 app[web.1]: Completed 500 Internal Server Error in 4ms

2012-07-18T06:13:31+00:00 app[web.1]:
2012-07-18T06:13:31+00:00 app[web.1]: ActionView::Template::Error (undefined met
hod `find_by_remember_token' for #<Class:0x00000004960740>):
2012-07-18T06:13:31+00:00 app[web.1]:     6:         <ul class="nav pull-right">

2012-07-18T06:13:31+00:00 app[web.1]:     7:           <li><%= link_to "Home", r
oot_path %></li>
2012-07-18T06:13:31+00:00 app[web.1]:     9:           <% if signed_in? %>
2012-07-18T06:13:31+00:00 app[web.1]:     11:             <li id="fat-menu" clas
s="dropdown">
2012-07-18T06:13:31+00:00 app[web.1]:     10:             <li><%= link_to "Users
", users_path %></li>
2012-07-18T06:13:31+00:00 app[web.1]:     8:           <li><%= link_to "Help", h
elp_path %></li>
2012-07-18T06:13:31+00:00 app[web.1]:     12:               <a href="#" class="d
ropdown-toggle" data-toggle="dropdown">
2012-07-18T06:13:31+00:00 app[web.1]:   app/helpers/sessions_helper.rb:10:in `cu
rrent_user'
2012-07-18T06:13:31+00:00 app[web.1]:   app/helpers/sessions_helper.rb:23:in `si
gned_in?'
2012-07-18T06:13:31+00:00 app[web.1]:   app/views/layouts/application.html.erb:1
1:in `_app_views_layouts_application_html_erb___2533055855927805914_43132200'
2012-07-18T06:13:31+00:00 app[web.1]:
2012-07-18T06:13:31+00:00 app[web.1]:   app/views/layouts/_header.html.erb:9:in
`_app_views_layouts__header_html_erb__2547305690965663969_41244280'
2012-07-18T06:13:31+00:00 app[web.1]:
2012-07-18T06:13:31+00:00 heroku[router]: GET whizcollab.herokuapp.com/ dyno=web
.1 queue=0 wait=0ms service=22ms status=500 bytes=643
2012-07-18T06:13:37+00:00 app[web.1]:
2012-07-18T06:13:37+00:00 app[web.1]:
2012-07-18T06:13:37+00:00 app[web.1]: Started GET "/users" for 115.87.214.246 at
 2012-07-18 06:13:37 +0000
2012-07-18T06:13:37+00:00 heroku[router]: GET whizcollab.herokuapp.com/users dyn
o=web.1 queue=0 wait=0ms service=47ms status=500 bytes=643
2012-07-18T06:13:37+00:00 app[web.1]: Processing by UsersController#index as HTM
L
2012-07-18T06:13:37+00:00 app[web.1]: Completed 500 Internal Server Error in 1ms

2012-07-18T06:13:37+00:00 app[web.1]:
2012-07-18T06:13:37+00:00 app[web.1]:   app/helpers/sessions_helper.rb:10:in `cu
rrent_user'
2012-07-18T06:13:37+00:00 app[web.1]: NoMethodError (undefined method `find_by_r
emember_token' for #<Class:0x00000004960740>):
2012-07-18T06:13:37+00:00 app[web.1]:   app/helpers/sessions_helper.rb:23:in `si
gned_in?'
2012-07-18T06:13:37+00:00 app[web.1]:   app/controllers/users_controller.rb:48:i
n `signed_in_user'
2012-07-18T06:13:37+00:00 app[web.1]:
2012-07-18T06:13:37+00:00 app[web.1]:
6
  • 1
    You can start with outputting what happens on Heroku, and what should happen. Commented Jul 18, 2012 at 5:54
  • herokuapp only shows this error on all pages "We're sorry, but something went wrong." Commented Jul 18, 2012 at 6:13
  • how i post heroku logs on here from cmd? it would look messy if i just copy it..please guide me :) Commented Jul 18, 2012 at 6:24
  • It depends on the operating system. If on osx: heroku logs | pbcopy, if on Linux: heroku logs | xclip Commented Jul 18, 2012 at 6:24
  • i added the heroku logs above :) Commented Jul 18, 2012 at 6:42

8 Answers 8

10

So I was also doing the Hart Tutorial and was coming into the SAME issue. I ran the heroku run db:migrate....i made sure it was up to date with git push heroku....I added a remember_key to my one user in the database. It was in the schema.rb file.

I finally found the answer:

user.rb:

add :remember_token to attr_accessible

Ex: "attr_accessible :name, :email, :password, :password_confirmation, :remember_token"

For some reason this is left out of the tutorial, even though now that i know whats wrong it makes sense. After adding this I re-pushed to heroku and Viola....

Hope this helps :)

Sign up to request clarification or add additional context in comments.

1 Comment

I just realized that my answer is the complicated version of Teoulas's comment "or you simply don't have that attribute" -- credit where credit is deserved :)
3

Dynamic finders only work if the attribute you're searching for exists. Either you didn't run all migrations or you simply don't have that attribute (remember_token) or you misspelled it.

Comments

3

I had the same problem and I've to say that IMHO it is not necessary to add :remember_token to the attr_accessible field. Doing that you expose the :remember_token, creating getters and setters, which is not necessary since :remember_token has to be considered as an internal variable. I solved the problem restarting the Heroku app, as confirmed here:

heroku-nomethod-error-remember-token

After rebooting the app was working correctly, as it was doing locally.

2 Comments

This worked brilliantly for me, thank you! (And I do agree that you shouldn't expose your :remember_token. It should be pointed out that it's not an error/omission on Hartl's part.)
just run heroku restart
1

It fails because it does not find the definition of the following method find_by_remember_token. I remember that remember_token is defined in the session_helperin the Hartl tutorial. It seems to arise when the signed_in? method is called.

Could you paste the session_helper.rb and User model code?

Comments

1

Try running heroku restart. It did the trick for me.

It should be noted that adding :remembered_token to your attr_accessible declaration is not recommended, as per r4m's answer. (There's a reason Hartl didn't do that in the tutorial.)

Comments

0

The line:

ActionView::Template::Error (undefined method `find_by_remember_token' for #<Class:0x00000004960740>):

is telling you that Rails doesn't know what 'find_by_remember_token' is, which means that it either doesn't exist (i.e it's a typo), or that the database, which is generally used to determine class properties, isn't aware of this field.

Assuming it's not a typo, then migrating your database would be an option:

heroku run rake db:migrate

Comments

0

I was getting the internal server error when I tried to push to heroku and also to amazon. I had to precompile my assets before pushing the app to the server. If this is your problem the easiest solution was to run

RAILS_ENV=production rake assets:precompile 

or add load 'deploy/assets' to the capfile, if you are using Capistrano. I was told you can add the following to your deploy.rb file, but I was not able to get it working.

after "deploy:restart", "deploy:precompile"

  namespace :deploy do

    desc "Compile assets"
    task :precompile, :roles => :app do
    run "cd #{release_path} && rake RAILS_ENV=#{rails_env} assets:precompile"
  end
end

Comments

0

What worked for me was defining the create_remember_token method in the User model exactly as described in the tutorial.

private
def create_remember_token
   self.remember_token = SecureRandom.urlsafe_base64
end

And then calling it in the before_save method.

before_save { 
    self.email.downcase!
    create_remember_token
}

I didn't have it as a method declaration before. And while it worked on my computer, it failed in Heroku.

#this failed in Heroku    
before_save { 
    self.email.downcase!
    self.remember_token = SecureRandom.urlsafe_base64
}

Also, it would do no harm to run:

heroku run rake db:migrate

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.