here’s what I’m trying to do right…. When a user signs in and is redirect to the landing page, I want to run a bit of jquery ajax to grab and inject some content.
I originally had it in my application.js file but the problem with that is that the code is there for user’s that aren’t logged in, which means I have to add logic to account for that which doesn’t seem clean.
What I’d like is for when the view is called to be able to include JavaScript…. I tried pasting it in the view file itself but that failed because it is loaded before JQUERY which is at the bottom of the page…
How do Rails 3 gurus handle this? Thanks!
Well, you could include the jQuery file at the top.
If that’s not an option, add
<%= yield :javascript %>in the layout below the jQuery include, and do:It will be placed in the proper location in your layout. (However, I’d recommend, for caching’s sake, that you write the Javascript in an external file and include it where necessary instead of using inline Javascript. Just good practice.)