Rails 4.1,让驱动程序知道编辑并再次使用_form.html.erb。我试着做以下事情:
<% = Form_for @user, :controller => "admin/users" do | f |%>
<button type='submit'>Guardar</button>
<% end %>
#Controller ===============
def new
@user = User.new
end
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html { redirect_to admin_users_url, notice: "User #@user.name} was successfully created." }
format.json { render :controller => 'admin/users', action: 'show', status: :created, location: @user }
else
format.html { render :controller => 'admin/users', action: 'new' }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
但它不起作用我无法进入我的控制器路径(“admin / users”),如果有人可以帮助我
答案 0 :(得分:0)
我假设您在config/routes.rb
中定义了管理路由,如下所示:
# in config/routes.rb
namespace :admin do
resources :users
end
请参阅:Rails Guide about namespaces in routes
然后,这应该适用于视图中的管理员命名空间表单:
<%= form_for [:admin, @user] do |f| %>
...
<% end %>
请参阅:Rails Guide about namespaces and form helper
您的控制器代码看起来没问题,但请确保控制器也是命名空间:
# in app/controllers/admin/users_controller.rb
module Admin
class UsersController
# ...
end
end