Can't run this Rails app - ruby-on-rails

Hey guys,
I clone a repo in Github: https://github.com/huacnlee/homeland/tree/
when I run the server, I got this error:
Agro:homeland Zhulin$ rails s
DEPRECATION WARNING: railtie_name is deprecated and has no effect. (called from <top (required)> at /Users/Zhulin/Desktop/RailsApps/homeland/config/application.rb:9)
/usr/local/lib/ruby/1.9.1/syck.rb:145:in `initialize': No such file or directory - /Users/Zhulin/Desktop/RailsApps/homeland/config/config.yml (Errno::ENOENT)
from /usr/local/lib/ruby/1.9.1/syck.rb:145:in `open'
from /usr/local/lib/ruby/1.9.1/syck.rb:145:in `load_file'
from /Users/Zhulin/Desktop/RailsApps/homeland/config/application.rb:48:in `<top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands.rb:28:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands.rb:28:in `block in <top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands.rb:27:in `tap'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
What should I do? And BTW where can I find simpler Rails code for learning Ruby and Rails,
Thanks

You need to set up a config.yml file in the config folder. It looks like the repo includes a config.yml.default file that you can use as a template.

It looks like you're missing your database configuration file config/database.yml for some reason. These are generated automatically by rails new <appname> so it is easy to get a replacement.
As for examples, a good reference book is always best. I like the Agile Web Development with Rails book, but there are many others.

Related

undefined method 'load_defaults' with Rails Generate

I'm really new to Ruby and its Rails framework and I was following a tutorial when I ran into some issues using the rails generate command. I tried using rails generate scaffold and rails generate controller but it didn't work. The full trace is this:
/usr/lib/ruby/vendor_ruby/rails/railtie/configuration.rb:95:in `method_missing': undefined method `load_defaults' for #<Rails::Application::Configuration:0x000055cdba53c180> (NoMethodError)
from /home/eric/Projects/blog/config/application.rb:12:in `<class:Application>'
from /home/eric/Projects/blog/config/application.rb:10:in `<module:Blog>'
from /home/eric/Projects/blog/config/application.rb:9:in `<top (required)>'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `require'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `preload'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from -e:1:in `<main>'
I think that the main issue is that I'm missing the 'load_defaults' method, but I couldn't find anything on how to resolve the issue. For context, I'm doing this all on a completely new rails project on Ubuntu - the only things I've done so far are rails new and bundle install.
Somewhat curiously, this issue is only popping up on new rails projects that I've created. I tried using rails generate commands on a project I had earlier and it worked. I couldn't figure out what was different between the projects though.
Any suggestions would be greatly appreciated!

Gemfile.old not found

I made some changes in the Gemfile but I wanted to keep track of what was in the previous one. So I just changed the old one to Gemfile.old expectind it would be ignored. But after some changes and running bundle the rails server simply stopped running due to not finding this file.
here is the log.
/Users/viniciusbolzani/.rvm/gems/ruby-2.1.5#global/gems/bundler-1.7.11/lib/bundler/definition.rb:22:in `build': /Users/viniciusbolzani/work/cart/Gemfile.old not found (Bundler::GemfileNotFound)
from /Users/viniciusbolzani/.rvm/gems/ruby-2.1.5#global/gems/bundler-1.7.11/lib/bundler.rb:155:in `definition'
from /Users/viniciusbolzani/.rvm/gems/ruby-2.1.5#global/gems/bundler-1.7.11/lib/bundler.rb:118:in `setup'
from /Users/viniciusbolzani/.rvm/gems/ruby-2.1.5#global/gems/bundler-1.7.11/lib/bundler.rb:134:in `require'
from /Users/viniciusbolzani/work/cart/config/application.rb:7:in `<top (required)>'
from /Users/viniciusbolzani/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121:in `require'
from /Users/viniciusbolzani/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121:in `require'
from /Users/viniciusbolzani/.rvm/gems/ruby-2.1.5/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:78:in `block in server'
from /Users/viniciusbolzani/.rvm/gems/ruby-2.1.5/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /Users/viniciusbolzani/.rvm/gems/ruby-2.1.5/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `server'
from /Users/viniciusbolzani/.rvm/gems/ruby-2.1.5/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/viniciusbolzani/.rvm/gems/ruby-2.1.5/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/viniciusbolzani/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:128:in `require'
from /Users/viniciusbolzani/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
from /Users/viniciusbolzani/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:39:in `require'
from /Users/viniciusbolzani/work/cart/bin/rails:8:in `<top (required)>'
from /Users/viniciusbolzani/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/client/rails.rb:27:in `load'
from /Users/viniciusbolzani/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/client/rails.rb:27:in `call'
from /Users/viniciusbolzani/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/client/command.rb:7:in `call'
from /Users/viniciusbolzani/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/client.rb:26:in `run'
from /Users/viniciusbolzani/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/bin/spring:48:in `<top (required)>'
from /Users/viniciusbolzani/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/binstub.rb:11:in `load'
from /Users/viniciusbolzani/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/binstub.rb:11:in `<top (required)>'
from /Users/viniciusbolzani/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/viniciusbolzani/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/viniciusbolzani/work/cart/bin/spring:16:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
Does anyone have a clue why Rails would be identifying that extension as a real file and requiring it?
I really think there is something wrong with your configuration.
Inside the bin directory inside your application there are a few executable files that specify how the Gemfile filename should be handled. The default file name is Gemfile but it may have been changed somehow.
I would suggest you execute
grep -R -i -n 'Gemfile.old' *
on the root of your application and check if there are any references somewhere with this name. And if that's the case change it accordingly.
There isn't any need to store the old version of Gemfile as rails considers all the gems mentioned in the file named as Gemfile , you can use versioning tools like github or bitbucket for this purpose .
Every time you add a new gem , the Gemfile.lock file adds the gem name and version to it just to make sure that it knows about the last change you made . In cases such as these , where you intend to keep multiple files of the same name , it might end up creating more confusion .Also the Gemfile.lock stores all the versions of the gem used so that you have an idea what all version numbers were used .

Mounting a rails engine within another rails engine

I have an application that is using a fork of a comfortable mexican sofa(comfy). I would like to mount mercury-rails onto comfy. The reason for this is so I can modify comfy to work with mercury.
I first added the gem for the engine into the comfy gemspec.
s.add_dependency 'mercury-rails'
ran bundle install
Then continued the guide to installing, running:
rails generate mercury:install
This gave me an error:
[WARNING] Could not load generator "generators/mercury/install/install_generator". Error: uninitialized constant Mercury::Engine.
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/mercury-rails-0.3.1/lib/generators/mercury/install/install_generator.rb:4:in `<class:InstallGenerator>'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/mercury-rails-0.3.1/lib/generators/mercury/install/install_generator.rb:3:in `<module:Generators>'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/mercury-rails-0.3.1/lib/generators/mercury/install/install_generator.rb:2:in `<module:Mercury>'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/mercury-rails-0.3.1/lib/generators/mercury/install/install_generator.rb:1:in `<top (required)>'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/generators.rb:280:in `block (2 levels) in lookup'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/generators.rb:276:in `each'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/generators.rb:276:in `block in lookup'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/generators.rb:275:in `each'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/generators.rb:275:in `lookup'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/generators.rb:137:in `find_by_namespace'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/generators.rb:154:in `invoke'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/commands/generate.rb:11:in `<top (required)>'
/Users/DickieBoy/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/commands.rb:48:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Now I think this is because I'm trying to install this on an engine and not an app. Which i guess engines aren't designed to do.
This error is also given if I try and run the same command from within the app.
NOTE this works when I add the gem to a standard rails app.
My questions are:
Is there any standards/documentation on mounting an engine within an engine?
If not, how would I go about doing this?
Make sure your library is also defined here: https://github.com/comfy/comfortable-mexican-sofa/blob/master/lib/comfortable_mexican_sofa/engine.rb

Ruby on rails thin gem - local server db error

When I run rails s on cmd(windows) I got this error below... Can anyone hack this error?
I'm using thin gem for local dev environment. What do I need to chage?
C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/application/config
uration.rb:115:in `read': No such file or directory - C:/Sites/project/config/da
tabase.yml (Errno::ENOENT)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/appli
cation/configuration.rb:115:in `database_configuration'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_
record/railtie.rb:78:in `block (2 levels) in <class:Railtie>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/comma
nds.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Yes, the file C:/Sites/project/config/database.yml doesn't exist. Either move your database.yml to that location, or find the code that expects database.yml to be in that location and change it to point to where the file actually is.

problem on setting up ruby on rails

I just started learning ruby on rails with "Lynda Ruby on Rails 3 Essential Training".
I finished the installation, and created rails application by writing- "rails new app".
After that when I wrote - "rails server", that's what I saw:
C:\Users\Oded\sites\simple_cms>rails server
C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/mysql2/mysql2.r
b:2:in `require': 193: %1 is not a valid Win32 application. - C:/Ruby192/lib/r
uby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/mysql2/1.9/mysql2.so (LoadError
)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/my
sql2/mysql2.rb:2:in `<top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/my
sql2.rb:7:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/my
sql2.rb:7:in `<top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runti
me.rb:64:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runti
me.rb:64:in `block (2 levels) in require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runti
me.rb:62:in `each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runti
me.rb:62:in `block in require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runti
me.rb:51:in `each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runti
me.rb:51:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler.rb:11
2:in `require'
from C:/Users/Oded/sites/simple_cms/config/application.rb:7:in `<top (re
quired)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/comman
ds.rb:28:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/comman
ds.rb:28:in `block in <top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/comman
ds.rb:27:in `tap'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/comman
ds.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Can you please help me find the solution?
Happy holidays,
Oded
Looks like you're missing some gems! try running bundle install... then all should work.
EDIT: make sure that your Gemfile contains the line
gem 'mysql'
before running bundle install. Bundler will get you set up for mysql, dependencies and all.
You have to go to this website and follow the directions ...
http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using-ruby-with-it/
or in short download the connector mentioned in the article from mysql or a mirror site
Run this command:
gem install mysql --platform=ruby -- --with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32
Make sure you have the correct path to the mysql connector folder that has no spaces!!
After that is complete make sure you copy the libmysql.dll file from the connector library you unzipped and downloaded and placed that in the Ruby\bin file.
After that delete the connector libary and start it up by typing 'rails server' making sure your gem file has the line gem 'mysql' or gem 'mysql2' I'm not sure which one so try both. It sucks and they really need to fix this for windows.

Resources