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
Related
In my project with content_tag_for I had an error:
The content_tag_for method has been removed from Rails. To continue
using it, add the record_tag_helper gem to your Gemfile: gem
'record_tag_helper', '~> 1.0'
So, I added this gem to my Gemfile. $ bundle install returns:
Using record_tag_helper 1.0.0
I have restarted server, cleared Rails cache and so on, but I still have the same error, that content_tag_for method has been removed from Rails. I just have no more ideas why it doesn't work.
Share your ideas, please.
Looking at the Github page, the gem has not been updated in 2 years. Also the last update contains the message 'Prep for Rails 5'. I'm assuming that this gem isn't compatible with Rails 5.
I have added "require 'record_tag_helper'" to my application.rb file and now it works.
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.
I want to use ebayapi gem (https://github.com/codyfauser/ebay) with my rails 3.1 application.
If I add the gem in the Gemfile, rails doesn't run.
/Users/ssk/.rvm/gems/ree-1.8.7-2011.03/gems/money-1.7.1/lib/support/cattr_accessor.rb:7:in `cattr_reader': undefined method `id2name' for {:instance_writer=>true}:Hash (NoMethodError)
I removed the ebayapi gem and tried "require 'ebay'" but it said that "no such file to load".
Ebayapi gem works only with money 1.7.1 and I think that conflicts with rails 3.1 (maybe 3.0 as well).
Is there a way to workaround?
Thanks.
Sam
If it's truly incompatible, and you're up to fixing it yourself, then fork the projects in question on github, and update your Gemfile to point to your git repo (or even a local path to make editing a lot easier).
Here's an example:
gem 'money', :path => "~/dev/ruby/gems/money"
# or
gem 'money', :git => "git://github.com/my_account/money.git"
Once you've fixed it, send a pull request to the original project so they can include the fix.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
How do you upgrade from Rails 3 to Rails 3.1 beta?
This is what worked for me when updating an existing rails 3.0.8 project. Your mileage may vary...
Update the rails version specified in my Gemfile to use the latest release candidate:
gem 'rails', '3.1.0.rc4’
Update the bundle:
bundle update
Then update the project with the rake command:
rake rails:update
After cherry picking though the change conflicts I ran all my tests and they passed (yay!). I restarted the server and everything seems good so far.
However, this is not using the new asset pipeline yet. By that I mean the javascript and css (or sass) files are still being handled in the pre-pipeline manner. As I understand it, this is a perfectly viable option. But of course, I want the new goodness, so I believe the next steps are to include and additional gems (e.g. coffeescript, sass, uglifier, etc) and then to migrate the old files to the app/assets directory.
I found some details about that are here:
http://blog.nodeta.com/2011/06/14/rails-3-1-asset-pipeline-in-the-real-world/
Hope that was helpful.
I just upgraded from 3.0 to 3.1 by changing my Gemfile to:
gem 'rails', '3.1.0.rc1'
gem 'sqlite3'
gem 'sass'
gem 'coffee-script'
gem 'uglifier'
I also commented out the following line below in config/environments/development.rb
# config.action_view.debug_rjs = true
Finally, make sure you enable the asset pipeline in config/application.rb
config.assets.enabled = true
I'm not sure if you've already read the release notes http://weblog.rubyonrails.org/2011/4/21/jquery-new-default
Upgrading Rails
Update: be cautious of using your system rake, as rake has been upgraded.
bundle exec rake
ensures you'll be using the correct rake for a given rails project (source)
I suggest beginning with a fresh app, then copying in your specific app information while shifting your resources into the new asset/sprockets format.
An example
While converting an older rails 2.3.4
app to 3.0 I crashed and burned while
changing one file at a time over
within the project. Needless to say
that was a flawed strategy, but I did
learn a little along the way. I ended
up skipping 3.0 and moving to 3.1beta1
with a fresh app, and copied my app
and public folders in after getting
the migrations right. That move had a
couple of outstanding issues, the most
important being that I didn’t use
rails edge for creating the new app
(thanks for the tip RubyInside).
First snag the latest rails into an
easy to reference location:
cd ~/goodtimes
git clone
https://github.com/rails/rails.git
My path includes a ~/Desktop/Dropbox/
so my code is available everywhere.
Then refer to that rails exec for
building a new app:
~/goodtimes/rails/bin/rails new bacon --edge
Depending on the complexity of your database, you'll either want to create new migrations using the change syntax or leave them be:
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :title
t.text :body
t.timestamps
end
end
end
I had an issue deploying to Heroku, but theRubyRacer gem helped square that away. Here's an example of a simple Gem file:
source 'http://rubygems.org'
gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Asset template engines
gem 'sass'
gem 'coffee-script'
gem 'uglifier'
gem 'jquery-rails'
gem 'pg'
gem 'therubyracer-heroku', '0.8.1.pre3', :platforms => :ruby
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
group :test do
# Pretty printed test output
gem 'turn', :require => false
end
I suspect there will be community utilities to help you automate migration from older versions of Rails to the --edge.
References:
How to Play with Rails 3.1, CoffeeScript and All That Jazz Right Now
The Four Horsemen of Rails 3.1beta, Coffee-Script, jQuery, SCSS and Assets
Rails 3.1beta deployed to Heroku from your iPhone
Reversible Migrations
I recommend updating your Gemfile to use edge rails. For example:
gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'arel', :git => 'git://github.com/rails/arel.git'
gem 'rack', :git => 'git://github.com/rack/rack.git'
gem 'sprockets', :git => 'git://github.com/sstephenson/sprockets.git'
gem 'sqlite3'
# Asset template engines
gem 'sass', '~> 3.1.0.alpha'
gem 'coffee-script'
gem 'uglifier'
You can read more here http://pogodan.com/blog/2011/04/24/easy-edge-rails.
If i understood your question correctly this is how:
gem install rails --pre
I'm following Rails Tutorial, creating a micoroposts app and pushing to Heroku. I'm able to get everything working locally, but the push to Heroku, I get no error messages, but the link myurl.heroku.com/micoroposts gives me the message, "The page you were looking for doesn't exist."
I have successfully added the following to my Gemfile (and run bundle install), per the tutorial advice, but no luck:
gem 'rails', '3.0.3'
'sqlite3-ruby', '1.3.2', :group => :development
Any ideas what might be happening?
You need to put the gem requirements on several lines:
gem 'rails', '3.0.3'
gem 'sqlite-ruby', '1.3.2'
And don't worry too much about the group => development, Heroku takes care of db connections for you.
When you did heroku create it would have told you an application name 'some-name-you-typed-in', so your url would be http://some-name-you-typed-in.heroku.com to see if the application starts.