I am eager to try out DataMapper for a new Rails project. I created my project using the following command:
rails new project_name -m http://datamapper.org/templates/rails.rb
I decided to test out my application by running:
rails server
When I go to the generic home page that is created, I can't see any images. I get an error stating:
ActionController::RoutingError (No route matches [GET] "/assets/rails.png")
If I create any other scaffolds and visit those pages, I get similar errors about the stylesheets or javascript not found. I double checked to ensure that a regular Activerecord-rails application worked (which it did). I'm rather puzzled. Any help would be greatly appreciated. Thank you :)
For some reason, DataMapper's Rails template completely replaces the standard Gemfile with their own, which doesn't include any of the asset handling stuff (it also removes a handful of other things like jQuery support, TestUnit, ActionMailer...).
You'll want to add these back in to your Gemfile after setting up the new application:
group :assets do
gem 'sass-rails', '~> 3.1.5'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
Per Frederick's suggestion below, you'll also want to add this into your config/application.rb file:
require 'sprockets/railtie'
I opened an Issue and submitted a pull request to fix this.
Update: As of 1/5/2012, this is now fixed. The template behaves nearly identical to a standard Rails 3.1 app with the only change being ActiveRecord being replaced with DataMapper. Assets/jQuery support now works.
Related
I'm new to rails and working through Hartl's tutorial. Everything was fine until I tried to do the tutorial a second time and created another project trying to use the latest version of rails. When I try to load the rails server from the app folder I get the following error.
$ rails s
=> Booting WEBrick
=> Rails 4.0.4 application starting in development on
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/Users/sierra/Desktop/sample_app_2/config/environments/development.rb:1:in
`<top (required)>': undefined method `configure' for
#<SampleApp2::Application:0x00000101a74610> (NoMethodError)
My Gemfile is directly from the Hartl tutorial:
source 'https://rubygems.org'
ruby '2.1.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.4'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'rails_12factor', '0.0.2'
end
I resolved it by doing following step.
Step 1: go to Project_Root_Directory/config/environment/development.rb
Change this line
Rails.application.configure do
To
Your_Rails_Application_Folder_name::Application.configure do
For example my rails project folder name is 'Spree_demo' so Your_Rails_Application_Folder_name in the following line:
Your_Rails_Application_Folder_name::Application.configure do
will be replaced as
SpreeDemo::Application.configure do
Note: See underscore in your application folder name it gets removed.
Hope it works for you guys.
First set Ruby version before Rails new
I had the same problem and I tried the answer given and it had no impact.
I even tried changing the name to get rid of the underscore, and it had no impact.
The problem is that you did this:
$ rails new app_name
But your ruby version was probably 2.1.1 or something else. You want to do:
$ rvm 2.0.0
BEFORE you run the new app, and then when you set 2.0.0 in your Gemfile (as Hartl recommends) it falls into place.
I don't know WHY this works, and I hope someone will shed light on it, but I can tell you that this worked better than the answer that is currently in the lead.
That happened to me too. The problem was that I used one version of Rails to create the project. Then I changed the Gemfile to use another version of Rails and the system was using it to scaffold or run the server. Newbie problem!
Using the same version consistently should solve the problem. :-)
I posted a (probably way too long) answer in a similar question: rails - NoMethodError: undefined method `configure' for FirstApp. This thread actually started me on the way to my eventual solution, so I thought I'd post here as well just in case it's helpful to anyone else.
From what I can tell, the problem occurs when the app/config/initializers/development.rb (and production.rb) files are generated for a new project using some newer versions of Rails (I'm not sure in which version it started, I only tested Rails 4.1.4). Mr. Hartl uses Rails 4.0.8 for his tutorial, and that's the highest version I tested in which the new syntax doesn't occur.
In Rails 4.1.4, and maybe some other versions after 4.0.8, the first line in those files is generated as Rails.application.configure.do rather than, using a project called sample_app as an example, SampleApp::Application.configure.do as in 4.0.8.
I'm new to Rails so I don't know why this syntax changed in newer versions. I'm assuming it's intentional and somehow better than the old way. Most likely, Mr. Hartl will take it in to account in future editions of his tutorial that are updated for versions of Rails which include this change.
Until then, see my other answer in the question I mentioned above for a more thorough explanation of how I got around it on Windows 7, but the tl;dr of it is:
Make sure you're using the version of Rails specified for the tutorial (4.0.8) in your local repository/root development directory before you create your new project. Updating your Gemfile after creating the project is still important, but it won't solve this problem if the files themselves were generated with a newer version of Rails. You'll have to go in and edit that line manually in that case, as other users have suggested.
I had this issue when I messed around with my Gemfile. For example I have created the app using rails 4.0.2 or something like that then due to some errors I changed it to 4.1.1 that change cause this exact same problem in both development and production
I'm using bootstrap-sass gem in my Rails project with version 2.3.1.0. However, when pushed up to Heroku, I'm getting the Bootstrap 3 styles. I inspect the CSS style and it indeed does say Bootstrap version 3.
On local, the assignment seems to be correct. But equally perplexing, when I inspect the CSS file, it says Bootstrap version 3 despite displaying what looks like the Bootstrap 2.3 styles.
I think at one point, my bootstrap-sass gem was using the Bootstrap 3, but when I put it back to gem 'bootstrap-sass', '2.3.1.0', I'm getting this strange conflict. I really just want my Heroku app to display the styles correctly. Even though I'm pushing up my current local version to Heroku, it is still using Bootstrap 3 stylings.
Here's what I've got:
Gemfile:
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'bootstrap-sass', '2.3.1.0'
end
I've created a styles.css.scss file, where I have the line #import "bootstrap";Here's what it looks like on localhost:
Here's what it looks like on Heroku:
It sounds like your Gemfile.lock might be incorrect. Have you verified that the correct version of the bootstrap gem is defined in Gemfile.lock?
Also might be worth just checking nothing is set in the Heroku env variable BUNDLE_WITHOUT. See the Heroku gem docs.
Not sure why this worked, but I found the second answer here to work for me.
I added *= require bootstrap" right above " *= require_tree . in application.css.
Then ran "bundle install --without production", followed by "rake assets:precompile". Committed the changes to git and then pushed to heroku.
I've never had to specifically require bootstrap in the asset pipeline before, but it works!
I have an existing Rails 3.2.14 application that I am trying to add zurb-foundation to. I have added the zurb-foundation gem and run the installation generator.
My problem is that, whenever I try to load a page, I get this error:
couldn't find file 'foundation'
when Sprockets hits the
//= require foundation
line in application.js
The problem appears to be that the directory with the assets from the zurb-foundation gem are not being added to the load path. In contrast, I have an application that I generated more recently, including zurb-foundation from the beginning, and #asset_paths.asset_environment.paths includes the following
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jquery-rails-3.0.4/vendor/assets/javascripts",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/coffee-rails-3.2.2/lib/assets/javascripts",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/zurb-foundation-4.3.0/scss",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/zurb-foundation-4.3.0/js"
which are not included in the asset load path in the app I am updating. Instead, I am getting (with p #asset_paths.asset_environment.paths in the better_errors diagnostic window)
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jquery-ui-rails-4.0.4/app/assets/images",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jquery-ui-rails-4.0.4/app/assets/javascripts",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jquery-ui-rails-4.0.4/app/assets/stylesheets",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jquery-rails-3.0.4/vendor/assets/javascripts",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/coffee-rails-3.2.2/lib/assets/javascripts"
interestingly, if I run the console in development mode and look at Rails.application.config.assets.path, it includes:
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jquery-ui-rails-4.0.4/app/assets/images",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jquery-ui-rails-4.0.4/app/assets/javascripts",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jquery-ui-rails-4.0.4/app/assets/stylesheets",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jquery-rails-3.0.4/vendor/assets/javascripts",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/coffee-rails-3.2.2/lib/assets/javascripts",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/zurb-foundation-4.3.1/scss",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/zurb-foundation-4.3.1/js"
and that DOES include the zurb-foundation asset paths.
I have included gem 'zurb-foundation' in the assets group, in the development group, and outside any group. I am using zurb-foundation-4.3.1 in the new app.
My Gemfile assets group is:
group :assets do
gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier'
gem 'compass-rails'
gem 'zurb-foundation'
end
This problem seems similar to Sprockets::FileNotFound with ZURB Foundation, although Jurriaan did not mention the asset load path.
Any idea what I could be missing?
Thanks!
Have you tried restarting the webserver?
Update:
You said it runs fine in development, Have you tried to rake assets:clean and rake assets:precompile?
It was a problem with a gem that was preventing foundation's entries being added to the load_path. The gem involved was mongomapper-versioned.
By not loading that gem, the problem resolved. By adding the gem back, the problem recurs.
That gem has not had any activity for two years. I guess it's time to find something else.
I have a simple rails project (ruby 1.9.3, rails 3.2.13), and I am attempting to incorporate the Gumby CSS Framework. The framework requires Compass, with modular-scale.
For sake of completeness the majority of the post contains information, skip to the end for the actual problem.
The working directory is being watched with
$ compass watch`
Compass was incorporated into the project with:
compass create --app rails \
-l ./app/assets/stylesheets/gumby/ \
--using modular-scale
The contents of config/compass.rb is:
require 'modular-scale'
project_type = :rails
And the location of Gumby source (SCSS) is app/assets/stylesheets/gumby.
The resulting compiled css appears in public/assets/gumby/gumby.css.
The following is within my Gemfile
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'compass-rails'
gem 'coffee-rails', '~> 3.2.1'
gem 'modular-scale'
gem 'gumby-rails'
gem 'uglifier', '>= 1.0.3'
end
And bundle install completes without errors.
However...
The following error message appears on all served pages:
Sass::SyntaxError in Users#index
Showing PROJECT_ROOT/app/views/layouts/application.html.erb where line #5 raised:
File to import not found or unreadable: compass/typography/vertical_rhythm.
Load path: Sass::Rails::Importer(PROJECT_ROOT/app/assets/stylesheets/gumby/_base.scss)
(in PROJECT_ROOTr/app/assets/stylesheets/gumby/_base.scss)
After hours of tinkering, I am at a loss as to the reason why Sass cannot read the Compass library.
I believe I found the solution from https://stackoverflow.com/a/9021785/1280997.
Removing config/compass.rb and rebooting the server fixes the immediate problem, however I am now faced with:
Undefined mixin 'box-sizing'.
(in PROJECT_ROOT/app/assets/stylesheets/gumby/_base.scss)
Ok, after much digging, I've found a way to incorporate Gumby into Rails, however I've lost the ability to edit the scss in the process. I did this using the gumby-framework gem. Setup was simple, following the README.
When using rails new, the following gems are automatically included in a Gemfile:
gem 'sass-rails', '~> 3.1.5'
gem 'coffee-rails', '~> 3.1.1'
I'm not a huge fan of SASS, and I strongly dislike Coffeescript, and it's getting annoying having .scss and .js.coffee files in every new project.
How can I remove these gems from rails new so that they won't be included by default in every new project?
Thanks for any responses in advance.
To answer your question: You can always create your own template.rb and pass that into rails new using the --template or -m option. RailsWizard will even generate a template for you.
Let me also say that the default template doesn't generates any .scss or .coffee files, but it is a little annoying that the gems are bundled automatically. Mostly, though, you could ignore that they're installed--just remove those two lines from your Gemfile.