11155
(-- --)
September 26, 2014, 12:19pm
1
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
11155
(-- --)
September 26, 2014, 12:37pm
2
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
11155
(-- --)
September 26, 2014, 1:07pm
4
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" %>
if you should check it like
if params[:choice].to_s == “1”
#do something
else
#do something else
end
11155
(-- --)
September 27, 2014, 6:51am
6
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
(Colin Law)
September 27, 2014, 7:01am
7
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
(Colin Law)
September 27, 2014, 7:02am
8
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