简体   繁体   中英

How to install Foundation in Rails Engine 4.1.5

It seems that foundation doesn't seem to "play nicely" with rails engines. I am designing a style layout engine so that I can plug and play this engine into various backend apps. I would love to use foundation to do the design work but no matter what different installation techniques I try, I still seem to get the same errors:

I initially tried running:

$rails g foundation:install 

which returned:

"could not find generator foundation:install" 

I double checked my bundle, because I added zurb-foundation to my gemspec file. It was in my bundle, so I figured it was a compatibility problem with me using a rails engine instead of a regular rails app. To which I found this article: https://github.com/zurb/foundation/issues/1225

I tried following @ivansnek's directions. Which gave me these errors in my chrome console:

foundation.js?body=1:26 Uncaught TypeError
foundation.alerts.js?body=1:58 Uncaught ReferenceError: Foundation is not defined
foundation.clearing.js?body=1:517 Uncaught ReferenceError: Foundation is not defined
foundation.cookie.js?body=1:75 Uncaught ReferenceError: Foundation is not defined
foundation.dropdown.js?body=1:184 Uncaught ReferenceError: Foundation is not defined
foundation.forms.js?body=1:556 Uncaught ReferenceError: Foundation is not defined
foundation.joyride.js?body=1:853 Uncaught ReferenceError: Foundation is not defined
foundation.magellan.js?body=1:137 Uncaught ReferenceError: Foundation is not defined
foundation.orbit.js?body=1:432 Uncaught ReferenceError: Foundation is not defined
foundation.reveal.js?body=1:354 Uncaught ReferenceError: Foundation is not defined
foundation.section.js?body=1:431 Uncaught ReferenceError: Foundation is not defined
foundation.tooltips.js?body=1:210 Uncaught ReferenceError: Foundation is not defined
foundation.topbar.js?body=1:371 Uncaught ReferenceError: Foundation is not defined
foundation.interchange.js?body=1:281 Uncaught ReferenceError: Foundation is not defined
foundation.abide.js?body=1:195 Uncaught ReferenceError: Foundation is not defined
application.js?body=1:15 Uncaught ReferenceError: $ is not defined

I then tried the regular ol' manual installation guide on foundation's documentation here: http://foundation.zurb.com/docs/applications.html which gave me the same errors listed above. Has anyone run into these problems, and can point me in the direction of the right documentation, or explain to me how you successfully installed foundation into a rails engine? As an ending note, foundation seems to be working just fine in my dummy app. It's just in my actual engine where I can't get it to play nicely. In my dummy app, I was able to run the foundation install generator successfully. My actual engine requires a manual installation instead of a rails generator.

EDIT:

I added the gem 'foundation-rails'. So now I have the zurb-foundation gem AND the foundation-rails gem included in my engine. This got rid of the 'Uncaught ReferenceError' errors I was getting. But now the reference to jQuery is not working. My google console error says "jQuery is not defined." This leads me to believe that the manual installation is still not going well. I am referencing foundation in my application.js like:

//= require foundation
$(document).foundation();

There is a known issue with foundation-rails not being able to install correctly into rails mountable engines. I am currently submitting a pull request and will update this answer once a solution comes about.

First off - get rid of the zurb-foundation gem. It is dead (last release was 2013) and having two different versions of Foundation in your gem is just going to cause headaches.

I recently encountered this issue with foundation-rails 5.5.1.1 in a normal rails app. It seems to be due to a bug where plugins are required before foundation/foundation (the "core") which is fixed in a commit but has not yet been released.

You can either use the master branch off github:

gem 'foundation-rails', github: "zurb/foundation-rails"

Or require 'foundation/foundation' before 'foundation' in your sprockets manifest:

//= require 'jquery'
//= require 'foundation/foundation' 
//= require 'foundation'

Make sure to have the following line in your Gemfile :

gem 'zurb-foundation'

After that you have to run the bundle command. Then try again to

rails g foundation:install

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM