Jean
Jean

Reputation: 5411

Adding a javascript file to my assets

I have a view with the following namespace

view/kids/registration/new.html.haml

Now I need to create a js file to this view, so I created a file in the following path:

assets/javascripts/kids/registration/new.js

Then I add the following lines to the application.js:

//= require ./kids/registrations/new

But it does not work. What I'm doing wrong. I'm checking the DOM (localhost:3000/kids/sign_up) but I never find line with this javascript file.

Thanks in advance for your help.


Adding the route

new_kid_registration GET /kids/sign_up(.:format) frontend/registrations#new

What I'm doing wrong.

Thanks.

Upvotes: 0

Views: 54

Answers (2)

Aks..
Aks..

Reputation: 1403

I had faced similar problems while adding stylesheets to assets (Link to my question)

Here are few things you might wanna try:

  • As suggested by BOB add the require statements to application.js

  • I remember adding the list of files to application.rb as:

       config.assets.precompile += ['jquery.colorbox.js','colorbox.css', 'reportng.css', 'reportng.js'] 
    
  • Your JS file can be placed anywhere in lib/assets/javascripts, assets//assets/javascripts & vendor/assets/javascripts
  • Try using the <%= javascript_include_tag "your_js_file_name" %> in your view file

Upvotes: 0

Bob
Bob

Reputation: 2121

Try //= require kids/registrations/new or //= require kids/registrations/new.js

Upvotes: 1

Related Questions