2
編集ユーザー登録フォームに2つのチェックボックスを追加しようとしていますが、フォームを送信するときに属性が更新されません。 "twitter_share" => "1"、 "facebook_share" => "1"と表示されますが、これはデータベースに登録されません。Rails 3:フォームでチェックボックスを使用する方法
私は何が間違っていますか?
フォーム:
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :validate => true, :html => { :method => :put }, :html => {:multipart => true}) do |f| %>
<%= devise_error_messages! %>
<p><%= f.check_box_tag(:twitter_share) %>
<%= f.label_tag(:twitter_share, "Share to Twitter") %></p>
<p><%= f.check_box_tag(:facebook_share) %>
<%= f.label_tag(:facebook_share, "Share to Facebook") %></p>
<p><%= f.label :email %><br />
<%= f.text_field :email %></p>
<p><%= f.label :name %><br />
<%= f.text_field :name %></p>
<p><%= f.label :username %><br />
<%= f.text_field :username %></p>
<p><%= f.label :bio %><br />
<%= f.text_field :bio %></p>
<p><strong>In order to change password:</strong></p>
<p><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password %></p>
<p><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></p>
<p><%= f.label :current_password %> <i></i><br />
<%= f.password_field :current_password %></p>
<p><strong>---------------------------</strong></p>
<strong>Avatar</strong></br />
<div class="avatar">
<%= image_tag(@user.avatar_url(:avatartiny).to_s) if @user.avatar? %>
<%= f.file_field :avatar %>
<%= f.hidden_field :avatar_cache %><br />
</div><br />
<p><%= f.submit "Update" %></p>
<% end %>
Userモデル:
attr_accessible :email, :password, :password_confirmation,
:remember_me, :name, :avatar, :username, :bio, :twitter_share, :facebook_share
形式のログを提出する:twitter_share
とfacebook_share
パラメータがuser
パラメータの外にあるどのように
Started POST "/users" for 127.0.0.1 at 2011-06-17 13:00:48 -0700
Processing by RegistrationsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"UVzD3cczDsHlBC9uRpDA+1kkIwV5OL9r6jlH4egbwVI=", "twitter_share"=>"1", "facebook_share"=>"1", "user"=>{"email"=>"[email protected]", "name"=>"Example user", "username"=>"Example", "bio"=>"", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "current_password"=>"[FILTERED]", "avatar_cache"=>""}, "commit"=>"Update"}
User Load (1.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1
WARNING: Can't mass-assign protected attributes: current_password, avatar_cache
SQL (0.2ms) SELECT 1 FROM "users" WHERE (LOWER("users"."email") = LOWER('[email protected]')) AND ("users".id <> 2) LIMIT 1
SQL (0.2ms) SELECT COUNT(*) FROM "authentications" WHERE ("authentications".user_id = 2)
SQL (0.1ms) SELECT 1 FROM "users" WHERE ("users"."username" = 'Example') AND ("users".id <> 2) LIMIT 1
CACHE (0.0ms) SELECT 1 FROM "users" WHERE ("users"."username" = 'Example') AND ("users".id <> 2) LIMIT 1
Slug Load (0.4ms) SELECT "slugs".* FROM "slugs" WHERE ("slugs".sluggable_id = 2 AND "slugs".sluggable_type = 'User') ORDER BY id DESC LIMIT 1
AREL (0.3ms) UPDATE "users" SET "bio" = '', "encrypted_password" = '$2a$10$hu1TyBa.75o6rlfx9GF3herU15Jl87nKxmT9i3h6erCHFX20.2fze', "updated_at" = '2011-06-17 20:00:48.822900' WHERE "users"."id" = 2
Redirected to http://localhost:3000/
Completed 302 Found in 372ms
素晴らしいおかげで、今私は新しいエラーhttp://www.pastie.org/2084453任意のアイデアを得ています? –
ブラケットを取り外しますか? – Zabba
ブラケットがなくても同じエラーが発生します。http://www.pastie.org/2084500 –