It can also be handy to have a main document ready block in the layout
file:

<% javascript_tag do -%>
  $(document.ready(function() {
    <%= yield :document_ready %>
  });
<% end -%>

Then you can drop page-specific JS into it with content_for. You'll
also be in an ERB context, so you'll have a lot more luck getting your
example above (using <%= %>) to work.

I find this a lot more straightforward than stuffing every bit of JS
into application.js, as it puts the code closer to the HTML it's
designed to manipulate.

--Matt jones

On Jun 4, 8:21 am, Bharat <[email protected]> wrote:
> application.js is a place to park your custom javascript routines.
> Therefore, the document ready call that you have there does not make
> sense:
>
> > $(document).ready(function() {
> >   $('#add_option').click(function() {
> >     $(this).addPollOption();
> >   });
>
> Put call in your "layout" file(s), e.g., application.html.erb for
> example.  You can even add it to the "erb" files where you need this
> functionality.
>
> Also, you need to follow Ryan's screencast more closely.  You will
> notice that he has the javascript code to append the partial in
> create.js.erb file.  That is extremely important.
>
> It is quite common to have Javascript "snippets" in various files and
> have multiple document ready calls in place.  It is a bit different
> than what we are used to as Ruby or Ruby on Rails programmers but it
> is best to get used to it.  It is better than Obstrusive Javascript :)
--~--~---------~--~----~------------~-------~--~----~
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