新手问题 ActionController::UnknownFormat 的问题无法解决

dxwts · May 16, 2014 · Last by dxwts replied at May 16, 2014 · 4832 hits

这个问题不知道该怎么办,求指导 用 devise 做用户管理,但我需要管理员可以改用户资料,所以加了个 people 的 controler,加了个 edit 的界面,在 edit 界面里 form 是

<%= form_for(@people, url: update_people_path(@people, :format => :html), html: { method: :patch }) do |f| %> 

routers 里

patch "update_people" => "peoples#update_people", as: "update_people", defaults: { format: 'html' }

controller

def update_people
  puts request.format
  @people = User.find(params[:user][:id])
  respond_to do |format|
    if @people.update(user_params)
      format.html { redirect_to peoples_path, notice: 'Produce was successfully updated.' }
    end
  end
end

总是在 respond_to do |format|报 ActionController::UnknownFormat,我在 form 和 routes 里指定了 format 也不管用,不知道为什么? rails4.0

試試去掉 if @people.update(user_params) 看看行不行。

@people.update(user_params) 返回 false 了?

#1 楼 @blacktulip 我刚刚也发现了,这个去掉可以正常跳转,这是为什么?

#2 楼 @saiga 确实返回 false 了

#3 楼 @dxwts 因爲你返回 false 的話,respond_to 就找不到對應的 format。你要加個 else format.html { blahblah } 處理這個情況。

谢谢二位,我查查为什么不能更新用户信息

You need to Sign in before reply, if you don't have an account, please Sign up first.