Reputation: 97
I am new to rails and devise. I developed a sample application with rails that has a registration model and registrations controller. So, when I add the devise to my application. It doesn't work!!. I think it is because devise use a controller named registrations and I have another controller named registrations in my application.
My specific problem is: User can not signed up. When I tried to signed up the application redirected to /registrations/user that is not existed and I've got the matching route error.
My RegistrationsController is looks like this:
class RegistrationsController < ApplicationController
def index
@registrations = Registration.all
respond_to do |format|
format.html
end
end
def show
@registration = Registration.find(params[:id])
end
def new
@registration = Registration.new 3.times { @registration.students.build }
end
def create
@registration = Registration.new(params[:registration])
if params[:file] != nil
import(params[:file])
end
if @registration.save
redirect_to @registration, :notice => "Successfully created registration."
else
render :action => 'new'
end
end
I'dont know how to solve this problem?? Please tell me how can I use another controller with different name rather than Registrations for the devise.
Upvotes: 0
Views: 1019
Reputation: 5095
Well, normally when you add the devise
gem into your project, it works out of the box. You don't need to create any controllers and views. It's all autogenerated for you with rails generate devise:install
.
So I would recommend just deleting your controller and rely on the Devise one.
However if the default behavior doesn't suit your needs, you can easily overwrite it by putting the following code in your routes:
devise_for :users, controllers: { registrations: 'registrations' }
and defining a controller like this
Users::RegistrationsController < Devise::RegistrationsController
def new
#overwriting the default behavior for new here
end
end
Note: I made some assumpptions with the above code.
Upvotes: 1