我的选择不起作用 这是我的表格 -
- @anonymous.each do |a|
=form_for @confession , html: {multipart: true} do |f|
=f.label :Confess
=f.text_area :confession , require: true
=f.label :post_as
=f.select(:postid,options_for_select([[@confession.amitian.fullname,@confession.amitian.fullname],[a.fullname,a.fullname]]))
=f.file_field :confessionimage
=f.submit 'Confess'
这是我的控制器类..
def index
@amitian = Amitian.where(institute: current_amitian.institute) if amitian_signed_in?
@confessions = Confession.where(amitian_id: @amitian.ids).order('created_at DESC') if amitian_signed_in?
@anonymous = Amitian.where(email: 'anonymous@anonymous.com')
@anonymous.each do |a|
@debug = a
if params[:postid] == 'Anonymous'
@confession = a.confessions.build
else
@confession = current_amitian.confessions.build
end
end
end
我的if语句永远不会是真的......为什么? 上面清楚的f.select语句是this =
f.select(:帖子ID,options_for_select('提供yourname''匿名&#39)
所以只要用户选择匿名if语句就应该返回true
答案 0 :(得分:0)
您需要在创建操作中检查params[:postid]
,而不是在索引中。