1
votes

After Googling everywhere about how I can fix this I decided to post a question. I'm trying to add a custom action "create_pro" to the Devise Registrations controller so I can create a user with additional fields (A pro user). This form is on the same page as the devise create action for a user.

I keep getting the following error after submitting the form:

Unknown action

The action 'create_pro' could not be found for Devise::RegistrationsController

How can I fix this?

Routes

  devise_for :users,:controllers => { :registrations => "registrations" }
  devise_scope :user do
    post "gopro", :to => "devise/registrations#create_pro"
  end

Registrations Controller

class RegistrationsController < Devise::RegistrationsController
  before_filter :authenticate_user!, :only => :token

  def new
    super
  end

  def create
    @user = User.new(params[:user])
    if @user.save
      sign_in @user
      flash[:notice] = "Welcome to Banking Analytics."
      redirect_to '/mybank'
    else
      render :action => :new
    end
  end

  def create_pro
    @user = User.new(params[:user])
    if @user.save
      sign_in @user
      flash[:notice] = "Welcome to Banking Analytics."
      redirect_to '/mybank'
    else
      render :action => :new
    end
  end
end

View

<div class="signup_form_basic">
<%= simple_form_for @user, :url => url_for(:controller => 'registrations', :action => 'create_pro') do |f| %>
  <%= f.error_notification %>
    <%= f.input :email, :required => true, :autofocus => true, :label => 'Username ( Your Email )', :placeholder => 'Email Address' %>
    <%= f.input :password, :required => true, :autofocus => true, :label => 'Password', :placeholder => 'Password' %>
    <%= f.input :password_confirmation, :required => true, :autofocus => true, :label => 'Confirm Password', :placeholder => 'Password Confirmation' %>
    <%= f.button :submit, "Sign Up  >>", class: 'btn btn-inverse' %>
<% end %>
</div>
1

1 Answers

1
votes

I don't have an answer for the 'Unknown Action error' that you are facing, but I think the current solution is sub-optimal.

Since your goal is to have the following two classes of users

  1. Pro-users, and
  2. Regular (Non-pro) users,

it is probably best to follow the suggestion at How To: Customize routes to user registration pages and set up parallel structures for the two types of users.

That would be much more in line with the relationship between the two types of users.