Ruby on Rails tutorial - generate question - ruby-on-rails

First attempt at a RoR project and following http://guides.rubyonrails.org/getting_started.html#creating-the-blog-application .
I've got the "Welcome Aboard" page serving.
Within the section 4.2 Say "Hello", Rails the tutorial says to issue the command :
$rails generate controller home index
... and that that will create a file
app/views/home/index.html.erb
... well as far as I can see it doesn't. In fact in the app/views directory there is no sub-directory called 'home' but instead one called 'layout' (which is empty)
When I issue a find command for index the file the file index.html.erb appears nowhere in the tree.
Can anyone provide me with advice on how to make that index.html.erb file (preferably in a manner compatiable with the tut !).
My environment is based on bitnami over ubuntu and looks like this :
Ruby version 1.8.7 (i686-linux)
RubyGems version 1.3.6
Rack version 1.0
Rails version 2.3.5
Active Record version 2.3.5
Active Resource version 2.3.5
Action Mailer version 2.3.5
Active Support version 2.3.5
Application root /home/bitnami/src/rubytest0/my_test_app
Environment development
Database adapter sqlite3
Database schema version 0

If you're using rails pre-3.0 try...
script/generate (instead of rails generate) in the root directory of your Rails project.
Older versions of rails don't allow 'rails generate', so you essentially created a new rails app called generate. As you continue to follow the tutorial, replace any instance of rails command with script/command if you are having trouble.

The tutorial you are referring to explicitly states:
"This Guide is based on Rails 3.0. Some of the code shown here will not work in earlier versions of Rails."
It looks like you are using rails 2.3.5

Related

/config/initializers/secret_token.rb not being generated. Why not?

Currently going through a rails tutorial and I need to make some modifications to /config/initializers/secret_token.rb, however, I can't find this file anywhere within the initializers directory. I am running the latest version of rails. This is the line I used in the terminal to create a rails project:
rails new sample_app
Anyone know why it isn't showing up?
Thanks for pointing this out. The issue is probably due to using Rails 4.1 instead of Rails 4.0 as specified in the Rails Tutorial. It's because of issues like this that Section 1.2.2 states (bold in original)
Unless otherwise noted, you should use the exact versions of all software used in the tutorial, including Rails itself, if you want the same results.
To get things to work, first uninstall the current version of Rails:
$ gem uninstall rails railties
Then follow the instructions exactly as written in the tutorial to install Rails 4.0:
$ gem install rails --version 4.0.4
Generating a test app (skipping Bundler for convenience) and piping the output through grep then verifies that secret_token.rb gets generated:
$ rails -v
Rails 4.0.4
$ rails new test_app --skip-bundle | grep secret_token
create config/initializers/secret_token.rb
At this point, you should be able to follow the rest of the tutorial as written.
By the way, I'm about to start work on a 3rd edition of the tutorial, and will plan to take care of this issue as part of a more general update.
The tutorial you're looking at was likely written for an older version of Rails than you're using.
secret_token.rb existed in Rails 3 and Rails 4.0 apps; it does not exist in Rails 4.1 apps.
It has been replaced in Rails 4.1 by the secrets.yml file:
http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml
I am using 4.1.1. Dont copy nothing to the secrets.yml, just dont forget to update the gitignore file (http://www.railstutorial.org/book/beginning#code-gitignore)
With this you can keep going on the tutorial

Ruby on Rails:-Rails s and Rails Server commands all create new projects

I am experiencing some weird rails behaviour:
When I do the following commands
rails new blog
rails s
rails server
The result for each is a new project, that is 3 folders names new, s, server, all with a new rails project in them
...why is this happening?? I have a feeling it may have to do with the versions I am using, I used rvm to update from 1.87 to 2.0 for Ruby and I just installed rails 2.3.14
I am using xubuntu which also just switched from Unity.
It looks like you are trying to use a Rails 3.x command with Rails 2.3. Pre 3.0 you have to use the server script.
From within your application directory run:
./script/server
Hope this helps.

When typing rails s or rails g, rails scripts are not run

First thing is I am on Ubuntu 12.04 LTS.
When I type rails s or rails g, a new rails app is created in folder /s and /g instead of the respective script being run.
When I type rails new, a new rails app with folder /new is created.
I'm not sure why this is happening. It only worked once when I first installed rails.
That's because you are using Rails 2.x. Check your rails version,
rails --version
to see your rails version.
new keyword is used in Rails 3.x. In Rails 2.x when you run command rails project it will create a project for you.
You need to invoke the local version of Rails via ./script/rails, instead of whichever version of Rails (obviously version 2.x) is installed system-wide.

can't create plugin with Rails 3.2?

i've a problem with rails in latest version.
I 've create a new app (rails new MyProject) but i don't have script/generate, only have script/rails and when i type
ruby ./script/rails generate plugin my_plugin
"Could not find generator plugin.".
Do you have any idea how generate plugin template?
it's possible to create plugin without this command?
PS: i'm using Rails 3.2.1 with ruby 1.8.7 [universal-darwin11.0]
The plugin generator has been removed with the release of Rails 3.2.0. See the changelog here. Now you can use the following command:
rails plugin new my_plugin
But be careful because you should run the command outside of the project. It creates a whole plugin structure with its own Gemfile. So, after created the plugin, you can use it in your Rails app adding it to the Gemfile with the path option. Something like:
gem 'my_plugin', path: '/path/to/my_plugin'
I just read that you're using Ruby 1.8.7. Please consider to upgrade to Ruby 1.9.3. Rails 3.2 is the last version of the framework that supports Ruby 1.8.7.

Ruby/Rails Command to get details on the app enviorment

I am working on a web application running on Rails 2.1 version.
I would like to know if there is any single command in rails or ruby that could fetch me in the console, all the details about my application like the version of my back end DB, Rails, Ruby and all relevant information pertaining to my web app.
This would help me to get all necessary details of my application without having to explicitly
look into each of the details one by one.
I think you can try the ruby script/about command for your rails app. This must work for the Rails 2.1 version.
Running this in the console would give you major environment details about your web application. Something similar to this :
Go to the app directory and run the command
$ ruby script/about
About your application's environment
Ruby version 1.8.7 (i486-linux)
RubyGems version 1.8.11
Rails version 2.1.2
Active Record version 2.1.2
Action Pack version 2.1.2
Active Resource version 2.1.2
Action Mailer version 2.1.2
Active Support version 2.1.2
Edge Rails revision e0a2f6c625d99d68df432a3c3418f4217bd56cbf
Application root /home/path/app_folder #path of your app directory
Environment production
Database adapter mysql
Database schema version 20101110130106

Resources