我试图为devise用户创建一个自定义的编辑表单,但是当我提交表单时,shell会抛出这个错误:
No route matches [POST] "/profile/12/edit"这是我的表格:
= simple_form_for(:user), html: { method: :put }) do |f|
= f.input :email
= f.input :username
= f.input :phone
= f.input :password, autocomplete: "off", required: false
= f.input :password_confirmation, required: false
= f.input :current_password, required: true
= f.button :submit, 'Update'这是我的profile_controller
class ProfileController < ApplicationController
def show
@client = Client.find(params[:id])
end
def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
redirect_to root_path
end
end
end和我的routes.rb:
Rails.application.routes.draw do
root 'home#index'
devise_for :users
resources :profile
end我哪里做错了?
发布于 2015-05-20 21:40:11
替换:
= simple_form_for(:user), html: { method: :put }) do |f|通过以下方式:
= simple_form_for @user, method: :put, url: "/profile" do |f|以下是一些错误:
控制器如果你想要编辑一个对象,提供它,而不仅仅是一个符号控制器必须将路径调整为指向/profile
put
post 发布于 2015-05-20 21:44:43
这就是我要做的:
= simple_form_for @user,
:url => url_for(:action => 'edit', :controller => 'profiles'),
:method => 'put' do |f| 在这里,您正在向ProfilesController的编辑操作提交一个PUT (更新)请求。
还要注意ProfileController和我写的ProfilesController之间的区别。Rails和DHH中的约定是模型名称应该是单数的,而控制器的名称应该是复数。
模型
class Profile < ActiveRecord::Base
end控制器
class ProfilesController < ApplicationController
endhttps://stackoverflow.com/questions/30350768
复制相似问题