jquery - Rails 3 - including JavaScript on a View? -


What I'm trying to do here .... When a user signs in and redirects to the landing page I will run some jquery ajax to catch some ingredients and to inject.

I originally had it in my application.js file but with that problem the code is for the user who is not logged in, which means that I add logic to the account for it That's not clean.

What do I want to do when the scene is called to be able to include javascript .... I tried to paste it in the visible file only, but it failed because it loads before jackmosis Which is in the lower part of the page ...

How are the three gurus handling it? Thanks!

OK, you can include the jQuery file at the top.

If this is not an option, in jQuery & lt;% = yield: javascript% & gt; Add and do:

  & lt;% content_for: JavaScript & gt; & Lt; Script type = "text / javascript" & gt; // code goes here & lt; / Script & gt; & Lt;% end% & gt;  

This will be placed in the proper place in your layout. (However, I used to recommend for caching, that you write javascript in an external file and include it where inline is necessary instead of using javascript.) Just good practice.)


Comments