Ruby on rails 行动';创建';找不到Admin::UsersController的
我被这个问题困住了,我无法确定问题所在。我正在尝试从管理部分添加一个用户。因此,我创建了一个自定义用户控制器,它调用Desive模型。我正在尝试使用自定义表单插入和更新值 控制器Ruby on rails 行动';创建';找不到Admin::UsersController的,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我被这个问题困住了,我无法确定问题所在。我正在尝试从管理部分添加一个用户。因此,我创建了一个自定义用户控制器,它调用Desive模型。我正在尝试使用自定义表单插入和更新值 控制器 class Admin::UsersController < ApplicationController load_and_authorize_resource before_action :configure_permitted_parameters, if: :devise_controller?
class Admin::UsersController < ApplicationController
load_and_authorize_resource
before_action :configure_permitted_parameters, if: :devise_controller?
before_action :authenticate_user!
layout 'admin-layout'
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit({ roles: [] }, :email, :password, :password_confirmation) }
end
def index
@user = User.all
end
def new
@user = User.new
end
def create
@user = User.new
if @user.save
redirect_to :action => "index"
else
render :action => "new"
end
end
def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
if @user.update_attributes
redirect_to :action => "index"
else
render :Action => "update"
end
end
def destroy
User.find(params[:id]).destroy
redirect_to ::Action => "index"
end
end
有人能告诉我哪里出了错。你定义了
新的
,创建
等方法。方法为受保护的
,如果你想让它们被识别为动作,它们需要公开
顺便说一句,在Ruby中,如果您有collection角色.all
,那么使用每个
而不是对
进行迭代会更具可读性(这里很少使用):
您定义了
新建
,创建
等方法作为受保护的,如果您希望将它们识别为操作,它们需要是公共的
顺便说一句,在Ruby中,如果您有collection角色.all
,那么使用每个
而不是对
进行迭代会更具可读性(这里很少使用):
我删除了受保护,但现在我得到了ActiveModel::ForbiddenAttributesError@Arun那就用吧。您的代码似乎有更多的问题——在开始使用Rails编码之前,为什么不先学习一下教程呢?有很多。是的,我知道强参数,我想允许角色参数,根据我已经包括配置允许参数方法。我删除了受保护的,但现在我得到了ActiveModel::ForbiddenAttributesError@Arun那就用吧。您的代码似乎有更多的问题——在开始使用Rails编码之前,为什么不先学习一下教程呢?有很多。是的,我知道强参数,我想允许角色参数,根据我包含的配置允许参数方法。
<div class="container">
<div class="col-md-6 col-md-offset-2">
<h2>Create New User</h2>
<%= form_for @user, url: {action: "create"} do |f| %>
<%= f.text_field :email, :class=>"form-control", :placeholder => "Enter Email", :required => "true" %>
<%= f.text_field :password, :class=>"form-control", :placeholder => "Enter Password", :required => "true" %>
<%= f.text_field :password_confirmation, :class=>"form-control", :placeholder => "Enter Password Again", :required => "true" %>
<p>Roles:</p>
<% for r in Role.all %>
<%= check_box_tag "user[role_ids][]", r.id %>
<%= r.name %>
<% end %><br/>
<%= f.submit "Create", :class=>"btn btn-primary" %>
<% end %>
</div>
<div>
admin_users GET /admin/users(.:format) admin/users#index
POST /admin/users(.:format) admin/users#create
<% Role.all.each do |r| %>