Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Ruby on Rails

Hey,

I am working on a personal project in the very early stages and I created new rails app added rspec/capybara. Created a scaffold for status updates and all is fine. I then decided to add foundation for quick styling using gem. It is all loaded and coming through except the JavaScript which is giving an error "Uncaught TypeError: Object [object Object] has no method 'foundation' " Googled my head off but nothing seems to be the right fix.

Any ideas or suggestions? Any details can be provided if you require

Thanks

2 Answers

Hey I got your back on this one hopefully. I ran into a similar issue a couple of times. The best solution is to install foundation system wide, or in your VM if you're using one. Not totally ideal, because that's a lot of extra weight into your program potentially and if you decide to stop using it, it's also slightly a pain in the rear to get out of your project. The second way I solved this was by deleting the turbolinks lines inside the main app layout html.erb file that foundation automatically installs. For some reason rails does not like this. I dont know why. Its only like one or two lines of code.

<%= javascript_include_tag "application", "data-turbolinks-track" => true %> <%= csrf_meta_tags %>

With this make sure all your JavaScript is then included just before the closing body tag. The third thing I did was in the app.js file, I removed the //=include_tree line, and added the JavaScript files separately if you have any others. I also removed the //= require turbolinks line.

I straight up don't have an answer for you as to why this works, and why the normal foundation install doesn't. I haven't figured it out, but I think it's a conflict with the turbolinks. Let me know if this helps any.

Thanks man this helped. Very strange though

I know this was answered but I'm wondering, which version of Rails were you using?

Chris Dziewa Version 4 :)

Thanks! That is strange. I could see that not working with Rails 3. At least you got it working!

Did you run the generator? rails g foundation:install https://github.com/zurb/foundation-rails

Yes, all the assets are coming though the pipeline but JS is giving the error object not found on 'foundation'