1

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.

1 Answer 1

1

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 -%>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.