can't create plugin with Rails 3.2? - ruby-on-rails

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.

Related

Missing step in downloading Ruby and crerating a new Ruby on Rails project on Windows

I am starting a new project that we decided to try out with Rails ... so I just installed Ruby via the Windows Installer and then, as is suggested on the Rails website, I run
gem install rails
rails new path/to/your/new/application
(replacing the path with my real project name) and I get the error that it failed complaining about JSON and that it can't build native extensions.
The Ruby on Rails home page tells you to install Ruby.
On the installer download page it says
If you don’t know what version to install and you’re getting started
with Ruby, we recommend you use Ruby 2.1.X installers
Ignore that. On the Ruby on Rails home page it says what version to install.
We recommend Ruby 2.2 or newer for use with Rails.
Then the Ruby on Rails home page says to run the following commands:
gem install rails
rails new path/to/your/new/application
cd path/to/your/new/application
rails server
The above won't work. The new rails project will fail.
What the steps above don't tell you is that, after running the installer, download and install the DevKit.
So ...
Download version of Ruby recommended on Ruby home page
Install Rails via gem install rails
Download DevKit
Then create Rails project by running last three commands above.

/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.

How do i start a cloned github project (ruby on rails)

i am just starting with RoR and working through some tutorials, there is however a particular piece of code on github that i would like to look at, i have cloned it to my local and cd into the project but 'rails s' does not seem to start the server - any ideas what i need to do?
That's a Rails 2.3.2 app. rails s was introduced in Rails 3, so you'll have to use the older script/server start command.
Also, you're going to need rails 2.3.2, which you can install with gem install -v=2.3.2 rails. There's also the possibility that you're missing some required gems, which you'll find out about by running the app and watching for load errors.
Also, make sure you're running Ruby 1.8.7, not Ruby 1.9.2. Rails 2.3.2 does not work with Ruby 1.9.2

Resources