我必须使用单选按钮或复选框在数据库中进行更新。如果我选中复选框(或单选按钮),它会进行更新,但是当我不选择它时,没有任何反应。
视图中的复选框部分:
Your curriculum is
"<%= form_for(:public, :url => {:action => 'public',:id=>@listCv.id}) do |f| %>
<%= f.check_box :public %> Public <br />
<%= submit_tag("Update") %>
<% end %>"
更新控制器就是这个:
def public
@cv=Cv.find(params[:id])
if @cv.update_attributes(params[:public])
redirect_to(:action=>'index')
else
#render :text=>@cv.id
render :text=>params[:privacidad] #just rendering to find why it does not make an update
#redirect_to(:action=>'index')
end
end
答案 0 :(得分:0)
因为你使用复选框我假设:public
是一个布尔值。
试试这个:
def public
@cv=Cv.find(params[:id])
public = params[:public]
public = false if public != true
if @cv.update_attributes(public)
redirect_to(:action=>'index')
else
#render :text=>@cv.id
render :text=>params[:privacidad] #just rendering to find why it does not make an update
#redirect_to(:action=>'index')
end
end