设计控制器导轨 [英] Devise controllers rails

查看:150
本文介绍了设计控制器导轨的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Rails 3,在ruby 1.8.7上。并用于认证。设计(1.1.3)。但它是一个相当大的社区网站,我正在建设,所以我有一个表格的配置文件和用户的表。并且每次用户注册它也应该生成一个配置文件,但在设计中我不允许控制器,所以我完全失去了..



编辑



现在它说

  undefined method` getlocal'为星期二,2010年12月28日11:18:55 +0000:DateTime 

然后,当我做一个名为date_time.rb的文件,使用此代码

  class DateTime 
def getlocal

end
end

并在我的应用程序控制器中要求它给我这个

 失败的参数数(1为0)

它就像它不知道任何所谓的设计,但在我的路线我有设计

  devise_for:users 


解决方案

您可以将Devise RegistrationsController子类化并添加您自己的逻辑create()方法,并调用其他方法的父类方法。

  class MyRegistrationsController< Devise :: RegistrationsController 
prepend_view_pathapp / views / devise

def create
super
#在此生成您的个人资料
#...
end

def update
super
end
end

如果要自定义包含在宝石内的Devise视图,则可以运行以下命令来生成应用程序的视图文件:

  rails generate devise:views 

您还需要告诉路由器使用你的新控制器;像:

  devise_for:users,:controllers => {:registrations => my_registrations} 


I'm using Rails 3, on ruby 1.8.7. And using for auth. devise (1.1.3). But it is a quite large community site i'm building, so i have a table for profiles and a table for users. And every time a user registers it should generate a profile also, but in devise i'm not allowed the controllers, so i'm completely lost..

Edit

Now it says

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

Then when i make a file in lib called date_time.rb with this code

class DateTime
  def getlocal
    "it works"
  end
end

And require it in my Application controller it gives me this

fail wrong number of arguments (1 for 0)

it is like it don't know anything called devise anymore, but in my routes i do have devise

devise_for :users

解决方案

You can subclass the Devise RegistrationsController and add your own logic in the create() method, and call the parent class methods 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 customise the Devise views that are packaged inside the Gem then you can run the following command to generate the view files for your app:

rails generate devise:views

You will also need to tell the router to use your new controller; something like:

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

这篇关于设计控制器导轨的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆