Reputation: 11137
I a have a link , on which when i click it passes a text to a variable named :alert like this :
<%= link_to 'Get started now !',play_path , :alert => 'OK' %>
on the page at play_path
i test to see if the value :alert exists , and if it does , i pass that value to a javascript function . My question is how can i pass that value to a javascript function ?
here is what i would like to do :
<% if :alert -%>
<script>
$.pnotify({
pnotify_title: ' <%= :alert %> ',
pnotify_text: 'it's ok',
pnotify_type: 'error'
});
</script>
<% end -%>
of course the code isn't correct , it's just for 'explanation' of what i mean.
Upvotes: 1
Views: 1677
Reputation: 7899
Well, in your controller you should have.
@alert = params[:alert]
I guess you have to use the link like this:
<%= link_to 'Get started now !',play_path(:alert => 'OK') %>
And you can use the @alert
variable in your views.
<% if @alert -%>
<script>
$.pnotify({
pnotify_title: ' <%= @alert %> ',
pnotify_text: 'it's ok',
pnotify_type: 'error'
});
</script>
<% end -%>
Upvotes: 1