Rails List wrote:
> Hunt Hunt wrote:
>> Hi to all,
>> 
>> I am a newbie in rails or ROR, can we use javascript in rails?
>> Any documentation or blog will be welcome.
>> 
>> Regards
>> Hunt
> 
> Hunt, looks like you have jumped into this question without bothering to 
> google for it first,  anyway...here is how you include them
> 
> <%= javascript_include_tag "yourjavascript.js" %>
> <%= javascript_include_tag :defaults %>
> 
> If you are looking for a working rails application, goto 
> http://www.classifiedscript.in and download Craigslist Clone 
> application.
> 
> Follow it and replicate your own as per your requirements. If you have 
> question on the craigslist clone, ask them in the forum.  Anything 
> regarding rails you can ask here.
> 
> Goodluck


You can use:

<% javascript :defaults, 'your_custom_java_page', 'another_page' %>

in your application layout file.

You can also create the following in your application_helper.rb file

def javascript(*files)
  content_for(:head) { javascript_include_tag(*files) }
end

And if you want specific content on a page you could place:

<%=  javascript('your_custom_file') %>

However, keep in mind that when you go to production later on, you'll 
want to probably combine all those files into one file, cleaned of white 
spaces, and I use a plugin called Asset Packager which instead of doing 
all of the above, does the following:

<%= javascript_include_merged :base %>

Which if you are in development mode, it knows to just use the defaults, 
but when you are in production mode, it knows to use the base_packaged 
files.

-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to