How to asign strong perameters using radio button checked value in rails

please help me to assign strong params

myapplication view:

<%= f.label :choose %> <%= f.radio_button :choice, "1" %> <%= f.label :choice, "New Presentation", :value => "1", :style => 'margin: -18px 25px 0' %>
    <span id="select">
    <%= f.radio_button :choice, "0" %>
    <%= f.label :choice, "Select Presentation", :value => "0",

:style => ‘margin: -18px 25px 0’ %>

  <div id="upload_pre" style="display: none; margin: 1%">
    <%= f.file_field :ppt %>
  </div>
  <div id="selection_pre" style="display: none; margin: 1%">

  <%= f.select :presentation_id,

options_for_select(current_user.presentations.collect {|s|
[s.avatar_file_name,s.id]}), :prompt => “Please select your
Presentation” %>

Myapplication webnaircontroller:

def create

@webnair = Webnair.new( webnairs_params )
def webnairs_params
if choice == 1
params.require(:webnair).permit(:user_id, :ppt, :choice, :title,
:description)
else
params.require(:webnair).permit(:user_id, :presentation_id, :choice,
:title, :description)
end
end
end

please anybody give me some solution…?

Is choice method defined anywhere ? >>>> " if choice == 1 "

And keep your permitted params method outside create.
def create

end

def webnairs_params
if choice == 1
params.require(:webnair).permit(:user_id, :ppt, :choice, :title,
:description)
else
params.require(:webnair).permit(:user_id, :presentation_id, :choice,
:title, :description)
end
end

Vivek S. wrote in post #1158513:

Is choice method defined anywhere ? >>>> " if choice == 1 "

And keep your permitted params method outside create.
def create

end

def webnairs_params
if choice == 1
params.require(:webnair).permit(:user_id, :ppt, :choice, :title,
:description)
else
params.require(:webnair).permit(:user_id, :presentation_id, :choice,
:title, :description)
end
end

Thank you very much for your response Bro.

yes I’ve created strong perams outside create.
No I don’t create anywhere choice method but i get choice value from
form tag i.e

<%= f.radio_button :choice, “1” %>
<%= f.label :choice, “New Presentation”, :value => “1” %>

<%= f.radio_button :choice, “0” %>
<%= f.label :choice, “select Presentation”, :value => “0” %>

Vivek S. wrote in post #1158518:

if you should check it like

if params[:choice].to_s == “1”
#do something
else
#do something else
end

sorry Bro it won’t work…

if you should check it like

if params[:choice].to_s == “1”
#do something
else
#do something else
end

On 26 September 2014 14:07, Sai Ch [email protected] wrote:

params.require(:webnair).permit(:user_id, :ppt, :choice, :title,

<%= f.radio_button :choice, “1” %>
<%= f.label :choice, “New Presentation”, :value => “1” %>

<%= f.radio_button :choice, “0” %>
<%= f.label :choice, “select Presentation”, :value => “0” %>

That does not make a variable called choice available in the
controller action, it should make it availble via the params hash
though. Check in development.log to check whether it is being passed
ok and put some debug in your code to see what is happening.

Colin

On 27 September 2014 07:51, Sai Ch [email protected] wrote:

Vivek S. wrote in post #1158518:

if you should check it like

if params[:choice].to_s == “1”
#do something
else
#do something else
end

sorry Bro it won’t work…

What do you mean it won’t work? If you don’t give us details of what
is happening then we cannot help. We are not telepathic.

Colin