Configure controller rails

I am using Rails 3, on ruby ​​1.8.7. And use for auth. develop (1.1.3). But this is a rather large community site that I create, so I have a table for profiles and a table for users. And every time a user logs in, he must generate a profile as well, but in development I do not allow controllers, so I completely lost ..

Edit

Now he says

undefined method `getlocal' for Tue, 28 Dec 2010 11:18:55 +0000:DateTime 

Then, when I create a file in lib named date_time.rb with this code

 class DateTime def getlocal "it works" end end 

And claim it in my application controller, it gives me this

 fail wrong number of arguments (1 for 0) 

it looks like he no longer knows anything called devise, but on my routes I have development

 devise_for :users 
+4
source share
2 answers

You can subclass the RegistrationsController and add your own logic to the create () method and call the methods of the parent class for everything else.

 class MyRegistrationsController < Devise::RegistrationsController prepend_view_path "app/views/devise" def create super # Generate your profile here # ... end def update super end end 

If you want to customize developer views that are packaged inside Gem, you can run the following command to create view files for your application:

 rails generate devise:views 

You will also need to tell the router to use the new controller; sort of:

 devise_for :users, :controllers => { :registrations => "my_registrations" } 
+15
source

There is no need to turn on the controller; models can (and should) do all the heavy lifting here.

I assume that you have a relationship between the User and Profile models, in which case you should just do something like this:

 class User < ActiveRecord::Base has_one :profile # could be a belongs_to, but has_one makes more sense after_create :create_user_profile def create_user_profile create_profile(:column => 'value', ...) end end 
+6
source

Source: https://habr.com/ru/post/1333563/


All Articles