私のアプリでは、管理者ユーザーが「投稿」の1つの属性を編集できるようにしようとしています
投稿モデルは次のとおりです。
class PostsController < ApplicationController
before_filter :admin_user, only: [:edit, :update]
def edit
@post = Post.find(params[:id])
end
def update
@post = Post.find(params[:id])
if @post.update_attributes(params[:post][:some_attr])
flash[:success] = "Post updated"
redirect_to posts_path
else
redirect_to root_path
end
end
編集ビューは次のとおりです。
<% provide(:title, "Edit post") %>
<h1>Update the post</h1>
<div class="row">
<div class="span6 offset3">
<%= form_for(@post) do |f| %>
<%= f.label :some_attr %>
<%= f.text_field :some_attr %>
<%= f.submit "Save changes", class: "btn btn-large btn-primary" %>
<% end %>
編集ページの some_attr test_field に「123」を入力しようとすると、エラーが表示されます。
NoMethodError in PostsController#update
undefined method `stringify_keys' for "123":String
Application Trace | Framework Trace | Full Trace
app/controllers/posts_controller.rb:22:in `update'
Request
Parameters:
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"EdTg+cFBnZY447oSDqSTPfb/PJ6VisJOrQ8kvichDrE=",
"post"=>{"some_attr"=>"123"},
"commit"=>"Save changes",
"id"=>"17"}
何が問題なのですか?パズルのどのピースが欠けていますか?
ありがとう