我有一个我为Devise创建的控制器,我想用它来添加几个页面/ devise / registration /
class RegistrationsController < Devise::RegistrationsController
skip_before_filter :detect_account_ended
def import
@title = "Import customers from Quickbooks"
end
def categories
@title = "Edit Categories"
@categories = current_user.categories
respond_to do |format|
format.html # index.html.erb
format.json { render json: @categories }
end
end
protected
def after_update_path_for(resource)
edit_user_registration_path
end
end
我创建了路线
devise_for :users,
:path_names => {
:sign_up => "register",
:destroy => "logout" },
:controllers => {
:registrations => :registrations } do
get '/users/sign_out' => 'devise/sessions#destroy'
get '/users/import' => 'devise/registrations#import'
get '/users/categories' => 'devise/registrations#categories'
end
和观点。视图显示正确,但我从注册控制器传递的对象不会进入视图。如何解决这个问题,以便将这些对象传递给我的视图?
答案 0 :(得分:0)
尝试直接访问它们,如下所示:
current_user.categories
由于current_user
在视图中也可用,对于@title,您不必将其作为变量传递,因为您也可以直接将所需文本添加到视图中。