ImranNaqvi ImranNaqvi - 4 months ago 30
Ruby Question

Two views for Registration In Devise - Ruby on Rails

I'm in a confusing situation . I am using Devise for authentication in my application . And i want two different views for my Registration process . In my views i put them both in

devise/Registration
folder

1-business.html.erb
2-new.html.erb


But i got no way to access that 'business' file view . I have only one model
User
and i need these two views due to a flag in the
user table
. I can not also redriect according to their
falgs
like
current_user.myflag
because i need to do it even before registration .I checked some links too but they are different from my options -

Updated:
I have tried overriding Devise Registration controller like below but that also didn't helped me .

class Users::RegistrationsController < Devise::RegistrationsController
def business
end
end


As the business method is empty - It didn't gave the devise the good idea about resource name and type etc . I also tried

def business
resource = User.new
end


But never worked
Any help will be greatly apprecaited . thanks

Answer

I believe we had the same problem when i wanted to put devise registration to other views and i gotten the same problem. undefined resources or nil to fix this issue you need to initialize the resource somehow. One way is to initialize resource in the helpers/application_helpers: so you can call it to any views. note: resource here is user

 def resource_name
    :user
  end

  def resource
    @resource ||= User.new
  end

  def devise_mapping
    @devise_mapping ||= Devise.mappings[:user]
  end

I hope it helps you solve your problem.

Comments