addis_a
September 26, 2014, 2:19pm
1
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
sai_c
September 26, 2014, 2:37pm
2
please anybody give me some solution…?
sai_c
September 26, 2014, 2:42pm
3
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
sai_c
September 26, 2014, 3:07pm
4
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” %>
sai_c
September 27, 2014, 8:51am
5
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…
sai_c
September 26, 2014, 3:30pm
6
if you should check it like
if params[:choice].to_s == “1”
#do something
else
#do something else
end
sai_c
September 27, 2014, 9:03am
7
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
sai_c
September 27, 2014, 9:03am
8
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