Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6354707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:37:18+00:00 2026-05-24T22:37:18+00:00

This is the error I get: NoMethodError in Devise::RegistrationsController#create undefined method `trial_duration’ for nil:NilClass

  • 0

This is the error I get:

NoMethodError in Devise::RegistrationsController#create

undefined method `trial_duration' for nil:NilClass
app/models/user.rb:120:in `set_trial_end'

This is the relevant parts of my User.rb

before_create :set_trial_end

def set_trial_end
  plan = self.plan
  end_of_trial = Date.today + self.plan.trial_duration.days
  self.trial_end_date = end_of_trial.to_date
end

What’s strange is that if I look in my DB, for a user that is assigned a plan and look at the trial_duration attribute, I get a reply:

ruby-1.9.2-p0 > tu
 => #<User id: 29, email: "test50@abc.com", encrypted_password: "$2a$10$TKKQmBYem.vDq.mwDutv2u92Vick0X0jAIUQT6A9.FM....", password_salt: "$2a$10$TKKQmBYem.vDq.mwDutv2u", reset_password_token: nil, remember_token: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2011-06-18 23:03:12", last_sign_in_at: "2011-06-18 23:03:12", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", username: "test50", first_name: "Test", last_name: "Fifty", created_at: "2011-06-18 23:02:48", updated_at: "2011-06-18 23:03:12", invitation_token: nil, invitation_sent_at: nil, plan_id: 2, current_state: nil, confirmation_token: nil, confirmed_at: "2011-06-18 23:03:12", confirmation_sent_at: "2011-06-18 23:02:47", space_used: 0, failed_attempts: 0, unlock_token: nil, locked_at: nil, trial_end_date: "2011-07-02", active_subscription: nil, customer_id: nil> 
ruby-1.9.2-p0 > tu.plan
 => #<Plan id: 2, name: "Boutique", storage: 100.0, num_of_projects: 99999, num_of_clients: 10, cached_slug: "boutique", created_at: "2011-01-31 09:46:57", updated_at: "2011-08-11 08:22:48", amount: 19, trial_duration: 14, trial_duration_unit: "days", currency: "USD", billing_cycle: 28, billing_cycle_unit: "days"> 
ruby-1.9.2-p0 > tu.plan.trial_duration
 => 14
ruby-1.9.2-p0 > tu.plan.trial_duration.days
 => 14 days 

So not sure why Rails is giving me that error.

Any ideas?

Edit 1:

In my view, I have this:

<% if params[:promo] %>
    <%= text_field_tag "xcode", nil, :placeholder => "Coupon Code" %><br /> 
<%= hidden_field_tag(:plan_id, "1") %>
<% end %>

And in the POST, from my log, you can see the parameter plan_id set to 1

Started POST "/users" for 127.0.0.1 at 2011-08-24 03:11:07 -0500
  Processing by Devise::RegistrationsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"Jp2GHxnuVOVnI/sfr1CB4EQ9URCTJynv/2Ek4AiU8Lg=", "user"=>{"username"=>"test.user", "first_name"=>"Testing", "last_name"=>"User", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "email"=>"testuser@abc.com"}, "xcode"=>"testcouponcode", "plan_id"=>"1", "commit"=>"Register"}
nil

But I am still getting the error Plan can't be blank on the next page.

I have added the after_validation callback instead of after_create, so I no longer the NoMethodError. But the problem isn’t solved.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:37:18+00:00Added an answer on May 24, 2026 at 10:37 pm

    You’re using a before_create hook that’s assuming that self.plan is set:

    before_create :set_trial_end
    
    def set_trial_end
      #...
      end_of_trial = Date.today + self.plan.trial_duration.days
    

    And your error says:

    undefined method `trial_duration' for nil:NilClass
    

    So self.plan is nil during your set_trial_end call.

    Perhaps you want an after_create hook so that you’ll have some instance data to work with. Even then you’d want to check for self.plan.nil? (just in case) and use a validation to make sure you get one:

    class User < ActiveRecord::Base
      validates_presence_of :plan_id
      #...
    

    Or maybe an after_validation hook would serve you better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this error when trying to register a new user. NoMethodError (undefined method
This is the error I get: ContactPostalcardsController#skip (NoMethodError) undefined method `status=' for #<ContactPostalcard:0x2b21433d64b0> This
I get the following error: Delayed::Job SomeMailJob# (NoMethodError) undefined method `subject' for #<YAML::Object:0x2b0a191f4c78> This
I get this error: NoMethodError in Videos#new Showing /rubyprograms/dreamstill/app/views/videos/new.html.erb where line #1 raised: undefined
When i run my features i get this error: undefined method `visit' for #<Cucumber::Rails::World:0x81b17ac0>
i get this error {Method 'System.DateTime ConvertTimeFromUtc(System.DateTime, System.TimeZoneInfo)' has no supported translation to SQL.}
Why I get this error? Page not found (404) Using the URLconf defined in
I always get this error when trying to compile my file with Boost::GIL PNG
I get this error: Can't locate Foo.pm in @INC Is there an easier way
I get this error on an update panel within a popupControlExtender which is within

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.