ユーザープロファイルを編集するためのRuby on Railsページがあります。フォームには、ユーザー名と電子メールが正しく表示されます。テキストボックスの名前を変更して「更新」をクリックすると、「プロファイルは正常に更新されました。」というメッセージが表示されたedit_profileページに戻ります。問題は、名前をデータベースに保存しないように変更した値です。問題のレールを保存する
エラーはなく、サーバー出力のパラメータは正しく表示されます。
処理がUserController#更新(2009-05-19夜10時00分48秒で 127.0.0.1用)[PUT]パラメータ: { "ユーザ" => { "名" => "新しい名前" 、 "email" => "[email protected]"}、 "コミット" => "更新"、 "アクション" => "更新"、 "_メソッド" => "put"、 "authenticity_token" = > "59c79fa90aaf5558aaab8cddef6acb7a4c7c55c3"、 "ID" => "1"、 "コントローラ" => "ユーザー"}
私は何をしないのですか?
edit_profile.html.erb
<% form_for @profile, :url => {:action => "update", :id => @profile} do |f| %>
<%= f.error_messages %>
<p>Name: <%= f.text_field :name %></p>
<p>Email: <%= f.text_field :email %></p>
<%= f.submit "Update" %>
<% end %>
users_controller.rb
def edit_profile
@profile = User.find(current_user.id)
end
def update
@profile = User.find(params[:id])
respond_to do |format|
if @profile.update_attributes(params[:profile])
flash[:notice] = 'Profile was successfully updated.'
format.html { render :action => 'edit_profile' }
else
flash[:notice] = 'Profile Error.'
format.html { render :action => "edit_profile" }
end
end
end
EDIT: はい、これはこの問題を解決するために、命名の問題だった私は...
if @profile.update_attributes(params[:profile])
を変更
~
if @profile.update_attributes(params[:user])
はい、あなたは正しいです。トビーに感謝します。 – Mark