1
私は、ユーザプロファイル属性:show_hometown
を更新するフォームのcheck_box_tagを持っています。フォームを送信して:show_hometown
の値を切り替えると、属性の変更に関係なく、チェックボックス入力の値は「1」になります。誰かが私が間違っていることを理解するのを助けることができますか?ここでcheck_box_tagは、属性値がtrueまたはfalseのときに値を変更しません。
は私のフォームです:
def edit_show_hometown_settings
@profile = current_user.profile
if @profile.show_hometown == true
if @profile.update_attributes(:show_hometown => false)
redirect_to settings_path
else
redirect_to settings_path, :notice => 'Oops, something went wrong. Please try again.'
end
elsif @profile.show_hometown == false
if @profile.update_attributes(:show_hometown => true)
redirect_to settings_path
else
redirect_to settings_path, :notice => 'Oops, something went wrong. Please try again.'
end
end
end
そして最後に、私は:show_hometown
属性を作成するために使用される移行:
<%= form_tag({:action => "edit_show_hometown_settings", :controller => "profiles"}, :html => {:multipart => true }) do %>
<%= check_box_tag :show_hometown, 0, 1 %>
<%= @user.profile.hometown %>
<% end %>
ここで私は属性を更新するよどこからコントローラ内のアクションがあります:
t.boolean :show_hometown, :default => true