Redirect to a link with CoffeeScript

So while using CoffeeScript in my app, I wanted to redirect to another page in my rails app on a button click.  Now I didn’t want to make the button a link by itself using the “link_to” tag because I only wanted the button to redirect depending on certain criteria in Javascript (or coffee script).

As usual with CoffeeScript, its simple easy and elegant. To redirct to a link:

  $(".button").on "click", ->
    location.href = "your_rails_page"

This will redirect to
current_path/your_rails_page

Credit here

Advertisements

One Response to Redirect to a link with CoffeeScript

  1. Pingback: What I learned today | Redirect to a link with CoffeeScript

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: