Using devise 2.1.0
I am trying to send the new registration page a PricingPlan model.
So in my routes I have:
devise_scope :user do
delete "/logout" => "devise/sessions#destroy"
get "/login" => "devise/sessions#new"
get "/signup/:plan" => "devise/registrations#new"
end
And I override the devise registration controller. With this in my routes.rb to make it work:
devise_for :users, :controllers => {:registrations => "registrations"}
In my actual Registration controller which overrides Devise’s controller I have:
class RegistrationsController < Devise::RegistrationsController
view_paths = "app/views/devise"
def new
super
@plan = PricingPlan.find_by_name(params[:plan])
end
So that the default views still go to devise….
In my new view for the registration controller I call this:
<h3>You've chosen the <%= @plan.name %> plan.</h3>
And I get this error:
undefined method `name' for nil:NilClass
Also… in my PricingPlan model:
class PricingPlan < ActiveRecord::Base
has_many :users
And in my User model:
class User < ActiveRecord::Base
belongs_to :pricing_plan
I’m rather new at rails.
When I did a
raisein my registration controller, I realize that when I was hitting /signup/:plan it wasn’t hitting theregistrations controllerthat I had overode from devisesregistration controller.I figure out the reason:
Because I had made my own controller, the scope is no longer devises scope any more…
So this was WRONG:
This however is CORRECT:
So that part of my routes looks like this:
Everything else in the code stayed the same.
Thanks for @gabrielhilal for making me trace out the controller.