dimanche 29 janvier 2017

How to access Form.select values in rails

I havee this form where I want users to select how they wanna post .. with their name or as anonymous so this is my form for that

- @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'

Now I have a user with option to select either their name or anonymous to post for that I have to build post with anonymous or current_user m confused how to do that in controller this is what I have done so far

 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')
 if #params[:postid] == 'Anonymous'  # i need an if statement to check what user has selected .. can anyone help plz ?
 @confession = @anonymous.confessions.build
 else
 @confession = current_amitian.confessions.build 

end

plz I need help with this I need to complete this project soon thanx in advance

Aucun commentaire:

Enregistrer un commentaire