Why does this RegistrationsController customization not work?

32 views
Skip to first unread message

marcamillion

unread,
Dec 1, 2016, 3:40:16 PM12/1/16
to Devise
I am trying to simply create an instance variable that would be accessible in my `app/views/devise/registrations/edit.html.erb`, but it keeps coming back nil.

This is what I have done.

`app/views/users/registrations_controller.rb`:

class Users::RegistrationsController < Devise::RegistrationsController
 
def edit
   
if current_user_subscribed?
     
@plan = Stripe::Plan.retrieve(current_user.plan_name)
   
end
   
super
 
end
end


This is my `routes.rb`:


  devise_for
:users, controllers: {
    invitations
: 'invitations',
    registrations
: 'users/registrations'
   
},
    path_names
: { :sign_up => "register",
                 
:sign_in => "login",
                 
:sign_out => "logout",
                 
:settings => "settings" }


This is my `app/views/devise/registrations/edit.html.erb`:


    <% if current_user_subscribed? %>
     
<div class="col-md-12 subscribed-card">
       
<%= render partial: "subscriptions/card_brand", locals: { brand: current_user.card_brand, plan: @plan } %>
     
</div>
   
<% end %>



This is my `app/views/subscriptions/_card_brand.html.erb`

<div class="payment-card">
   
<div class="row">
     
<h2>Subscribed To: <%= plan.name %> for <%= formatted_price(plan.amount) %></h2>
   
</div>
</div>



But this is the error I am getting:


NoMethodError at /settings
undefined method `name' for nil:NilClass

What am I missing?

André Orvalho

unread,
Dec 6, 2016, 4:34:29 AM12/6/16
to Devise
You didn't give us the line where this error is happening but I am guessing it's here:

<h2>Subscribed To: <%= plan.name %> for <%= formatted_price(plan.amount) %></h2>

Have you tried an raised your @plan on the view to see if it's not nil?

Or raise inside of the controller to see if it is actually hit.
Reply all
Reply to author
Forward
0 new messages