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

35 views
Skip to first unread message

Sai Ch

unread,
Sep 26, 2014, 8:20:54 AM9/26/14
to rubyonra...@googlegroups.com
please help me to assign strong params

myapplication view:

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

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

<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" %>
</div>

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

--
Posted via http://www.ruby-forum.com/.

Sai Ch

unread,
Sep 26, 2014, 8:39:32 AM9/26/14
to rubyonra...@googlegroups.com
please anybody give me some solution.......?

Vivek Sampara

unread,
Sep 26, 2014, 8:41:54 AM9/26/14
to rubyonra...@googlegroups.com
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


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f12d7650177b00c44da841ae7f2a443f%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Sai Ch

unread,
Sep 26, 2014, 9:08:45 AM9/26/14
to rubyonra...@googlegroups.com
Vivek Sampara 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

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 Sampara

unread,
Sep 26, 2014, 9:29:27 AM9/26/14
to rubyonra...@googlegroups.com
if you should check it like

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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

Sai Ch

unread,
Sep 27, 2014, 2:51:57 AM9/27/14
to rubyonra...@googlegroups.com
Vivek Sampara 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....

Colin Law

unread,
Sep 27, 2014, 3:02:26 AM9/27/14
to rubyonra...@googlegroups.com
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

Colin Law

unread,
Sep 27, 2014, 3:03:09 AM9/27/14
to rubyonra...@googlegroups.com
On 27 September 2014 07:51, Sai Ch <li...@ruby-forum.com> wrote:
> Vivek Sampara 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
Reply all
Reply to author
Forward
0 new messages