Im trying to follow this tutorial.
Its about adding email confirmation after registration... The thing is when I submit the form I get this error
NoMethodError in UsersController#create
undefined method
`deliver_verification_instructions!'
for #
I looked at the code and indeed there is no such a method on my user model... Im very new at rails...Is the tutorial wrong??
Yes, tutorial has missed that method in User model. It should be something like this instead of deliver_password_reset_instructions:
def deliver_verification_instructions!
reset_perishable_token!
Notifier.deliver_verification_instructions(self)
end
I haven't checked that tutorial if rest is OK, but that was wrong for sure
Related
I am finishing the book and I've ignored this error message for too long. Please help me understand how to fix this. Thank you!
1) Error:
PasswordResetsTest#test_password_resets:
NoMethodError: undefined method reset_sent_at=' for #<User:0x007f814e118600>
app/models/user.rb:63:increate_reset_digest'
app/controllers/password_resets_controller.rb:12:in create'
test/integration/password_resets_test.rb:17:inblock in '
The error might point you a little bit into the wrong direction. This NoMethodError is actually caused by that fact that your users table doesn't have a column reset_sent_at.
Rails defines accessor methods (getters and setters) on your User model for each column in the users table. However, since it doesn't have a reset_sent_at column, no accessor is defined and the NoMethodError is being raised.
Make sure you've created the migration where reset_sent_at was added to users (this was done in chapter 10 of the Rails tutorial), and that you have executed the migration as well. After the migration, be sure to restart your Rails server.
So when I submit all the info to create a new user: i get this error:
NoMethodError in UsersController#create
undefined method `sign_in' for #
I googled for it first and found answers where I was supposed to create a sessions_helper.rb file and include it in application.rb , did it all and when I refreshed after each step, it seemed to work. But now when I reloaded the page from the start again, I got the same error again.
Veske showed me his code: https://gist.github.com/Veske/7536022
You have to define your method in the SessionHelper, it is not going to automatically be made for you :)
You need to create a sign_in method in at least the SessionsHelper class.
If you'd like to use the devise gem for users creation/authentication, you'll have that method available in your code directly.
I'm working with Spree 2.1 and trying to add new payment gateway, but this error is more generic so Spree itself is not-so-important here.
I have encountered that error (undefined method 'association_class' for nil:NilClass) after adding some module to Spree::PaymentMethod (source) class:
spree/payment_method_decorator.rb
Spree::PaymentMethod.class_eval do
include Spree::Core::CalculatedAdjustments
end
(Spree::Core::CalculatedAdjustments source)
(Spree::Gateway source)
Unfortunately, now Spree::PaymentMethod (source) breaks a little, i.e:
n = Spree::PaymentMethod.first
=> #<Spree::Gateway::Bogus id: 1, (...)>
n.save
=> undefined method 'association_class' for nil:NilClass
n.calculator
=> undefined method 'association_class' for nil:NilClass
Does anyone know why this happens and how to fix it?
In fact I already have an answer (after few hours of struggle), but maybe someone will give a better one with proper explanation. Maybe the answer is quite obvious, but it wasn't for me and I couldn't find anything related on SO so hopefully someone else with similar level of RoR knowledge won't have to spend another few hours on that.
So the answer was:
As it is visible in above links, Spree::Gateway is inheriting from Spree::PaymentMethod and my custom payment method was inheriting from Spree::Gateway class - something like:
module Spree
class Gateway::CustomMethod < Gateway
end
end
All I had to do was to include Spree::Core::CalculatedAdjustments in Spree::Gateway:
Spree::Gateway.class_eval do
include Spree::Core::CalculatedAdjustments
end
and it is working since then.
I have set up a staging instance of a rails 3.1 application on Heroku and everything seems to work fine except I'm getting a strange error when I try to send emails. I am using the sendgrid starter addon for email delivery. The full error is below:
NoMethodError: undefined method `index' for #<Mail::Message:0x000000048daf28>
/app/.bundle/gems/ruby/1.9.1/gems/mail-2.3.0/lib/mail/message.rb:1289:in `method_missing'
/app/.bundle/gems/ruby/1.9.1/gems/mail-2.3.0/lib/mail/encodings.rb:117:in `value_decode'
/app/.bundle/gems/ruby/1.9.1/gems/mail-2.3.0/lib/mail/encodings.rb:101:in `decode_encode'
/app/.bundle/gems/ruby/1.9.1/gems/mail-2.3.0/lib/mail/fields/unstructured_field.rb:74:in `do_decode'
if I just generate the message object without calling deliver on it and inspect it everything seems fine. I am not seeing this error on my production app. Can you tell me what this error means and how to resolve it? Thanks.
Got the same error on my local machine using Rails 3.0.11. It happened after I passed some object instead of a string to the mail :to attribute. So be sure that the :to attribute is a string!
mail(to: object.to_s)
A new version of Mail, Mail 2.4.0, was released this weekend. I would recommend upgrading to this latest version and seeing if that has fixed your issue.
This error was the result of using Class instead of Module when defining a mail helper I'd created.
This error happened because I was setting custom headers to an integer value. Using to_s on these values resolved the issue for me.
I had a similar problem. However, the error I received was:
NoMethodError (undefined method `ascii_only?' for nil:NilClass)
My problem was I had:
mail(to: emails,....)
And my variable "emails" was actually an array, instead of being one single string of emails.
Working with Rails 3 and Authlogic. I am following the steps on this tutorial: http://bit.ly/l8YOGg.
Signup/login/logout are all working fine and now I am adding email activation. I have used all the code exactly as listed on the tutorial, and when I attempt to sign in as a new user I get the following error:
NoMethodError in UsersController#create
undefined method `activate_account_url' for #<Notifier:0x00000103c4c9b8>
app/mailers/notifier.rb:6:in `activation_instructions'
app/models/user.rb:21:in `send_activation_instructions!'
app/controllers/users_controller.rb:17:in `create'
Can't find anything in the Authlogic documentation or elsewhere that helps. What am I doing wrong?
activate_account_url should be a named route. Did you define your routes correctly?
To find the correct route name, check rake routes, in particular rake routes | grep activate. Then put the correct route name into notifier.rb on line 6.