MID
MID

Reputation: 1825

How to add new action into Devise registrations controller?

I know how to override default controllers and it is working, but now I need to add new action into Registrations controller.

I need to update user fields. I need to add First and Last name in this form, but I don't want to use standard edit page, because it will be separate page.

So I need other page. I have paypal..html.erb in my registrations folder, but I can't render it from action in regustrations controller.

Paypal action:

class RegistrationsController < Devise::RegistrationsController

def paypal  
end 
...
end

routes.rb:

 devise_for :users, :controllers => {:registrations => 'registrations', :sessions => 'sessions'} do
    match 'paypal' => 'registrations#paypal'
  end

but somehow it render new registration file. Here is error:

   NoMethodError in Registrations#paypal
   Showing C:/1508/app/views/devise/registrations/new.html.erb where line #22 raised: 

How I can use update form to do this and what I'm doing wrong ?

Upvotes: 8

Views: 2809

Answers (2)

kitwalker
kitwalker

Reputation: 982

I added this to my routes to make it work

devise_scope :user do
  get 'paypal(/:id)', :action => 'paypal', :controller => 'user/registrations', :as => 'paypal'
end

Upvotes: 1

Kosmonaut
Kosmonaut

Reputation: 2290

Your question seems a little unclear, however Why not explicitly render the view?

def paypal
    render 'devise/registrations/paypal' 
end

If you have multiple type of users it may be better to separate out the paths and routing.

https://github.com/plataformatec/devise/wiki/How-To%3a-Customize-routes-to-user-registration-pages

Upvotes: 0

Related Questions