Problems while upgrading the rails version - ruby-on-rails

I'm a newbie to Ruby on Rails. My problem is, I am trying to upgrade the rails version from 1.2.3 to 2.3.4.
I changed the .rhtml files to .html.erb according to the rails version 2.3.4. I changed the environment and boot.rb settings according to the rails version, but when I try to run the application, I'am getting missing template error it is searching for the view with .rhtml extension but not for the html.erb. Please kindly help me with this.
Thank you

Did you change your RAILS_GEM_VERSION in the config/environment.rb file? It may still be looking for the 1.2.3 gem, as opposed to the 2.3.4 gem.

You can make sure whether you have upgraded properly or not by going to script/console and whether it prints out
Loading development environment (Rails 2.3.4)
or not as you enter the console, that might give you some hints.

Check if you have a copy of rails in the vendor directory. Also, what does script/about show?

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

Getting specific Rails version of a Rails 2.x app

Can figure out a Rails app being built on Rails 2.x , as it has a script/server file.
But How do I find which specific Rails version, the app is written in.
doc/README_FOR_APP for this app, does not seem to contain anything helpful in this regard. Any other way I can figure the specific Rails Version for the app.
Try using script/about at the command line.
It is defined in your config/environment.rb. Just run
./script/runner 'puts RAILS_GEM_VERSION'

Downgrading from Rails 3.2.6 to 3.0.11

I am facing issue when I am trying to work with rails 3.0.11. I initially worked with rails 3.2.6. Build a prototype application in Rails 3.2.6, Ruby 1.9.2 and gem 1.8.7. But then found, server on which we need to host is a shared server which can only support Rails 3.0.11, Ruby 1.8.7 and gem 1.7.2.
Hence I want to keep my dev environment exactly same before I ran into further issues. As I found there was some discrepancy in routes.rb of both the versions.
Steps I followed:
Uninstalled rails
Uninstalled ruby
Installed ruby from here.
This installed ruby version 1.8.7-p370 and gem 1.8.7
After this I installed rails by specifying version as 3.0.11
But still when I run command rails -v, it throws an error to me saying 'missing gem rails 3.2.6. Run bundle install to resolve the issue'
When I ran bundle install, it again completely installed rails 3.2.6 and problem remained unresolved.
Please suggest the clean way how shall I start my development on rails 3.0.11 without running into any issues?? Am I need to delete some registry or mapping in my system through which it is detecting rails 3.2.6 and creating issues??
Its urgent as I need to complete my dev by 7th September.
As I am new to stackexchange, please guide is it appropriate to ask question on the same related thread or shall I open new discussion for my problem?
#Gun - please note in response to one of your comments posted above - you DO need to change your Gemfile - if you are running rails -v from withing your project's directory, it will read the Gemfile.
There is a script located at script/rails - this is what runs when you run the rails command from the project directory. NOTE that this rails script requires your config/application.rb file - which in turn reads the Gemfile and bundles the referenced gems. Thus is your Gemfile still references 3.2.6, and it is not installed, rails -v will not work
Glad to hear the problem is fixed :)
As for the asset pipeline - if you are using rails 3.2.6 (or were using it) then you may have been using the asset pipeline to serve your assets (javascript files, CSS files, images, etc). If you were, and you downgrade to anything pre rails version 3.1, then anything being served through the asset pipeline will no longer work.
Here is a pretty good description of the asset pipeline: http://guides.rubyonrails.org/asset_pipeline.html
You should check also remove your Gemfile.lock or manually 'bundle update rails' when you change your rails dependency.
I suggest to use rbenv or rvm to create a virtual environment/sandbox where you can install your preferred ruby versions (e.g. 1.8.7) and keep tracking of your dependencies separately. This would save you a lot of effort.
Keep in mind that rails 3.0 has no asset pipeline support (it has been included in rails 3.1)! This is a very important difference and if you depend on it you will have big issues to solve for the downgrade.
Thanks a lot everyone for help.
I believe it was weird issue. I had heroku on the system. I was initially deploying my app on the same and then changed to another hosting server.
After uninstalling the heroku, it works perfectly fine. Probably, that was interfering somewhere. Although, not sure but problem is resolved.
Thanks a lot again for a great great help!!!
Meanwhile, I would request alup to throw some more light on asset pipeline support. Wots that? Could you please explain more??
Need to delete C:\Users\.ror folder and C:\Users\.gemfile and C:\Users\.gemfile.lock from your desktop..

Upgrading Rails

I have updated rails and have rails -v and it says 3.0.5. (which is good) when i open my old programs, will it still always use 3.0.4 as that is what was used?
And ..
when i create new one will it use 3.0.5
I have done this as i'm a newbie and having problems with tutorials from the rails by example book michael hartl and wondering if it is the version that is giving the problems.
Thanks for any help..
In Rails 3 Bundler was added to handle gem dependencies. Within each application a Gemfile exists that specifies the version of Rails to use. If you want to update an application change the version in your Gemfile and run bundle install.

Ruby on Rails: switching from rails 2.3.8 to 3.0.3

In my env I require 3.0.3
but when I script/server
I get this: can't activate rails (= 2.3.8, runtime) for [], already activated rails-3.0.3
I don't want it to activate 2.3.8.. =\
Rails 3.x doesn't use script/server anymore - you should run your server with rails server or rails s. You can delete all the files from script, except for script\rails.
Plus, you no longer specify your Rails version in environment.rb (if that's what you mean by "env"). All gems and their versions are specified in your Gemfile.
Did you follow a guide like Upgrading to Rails 3? It's not enough to just change the Rails version in evironment.rb.
The command to run the server in Rails 3 is rails server. What happens if you run that?
Rails 3 uses
rails server
command instead of
ruby script/server
Check environment.rb to make sure that you're not specifying rails 2.3.8 explicitly. If you are then you need to make sure you've upgraded to bundler properly.
My suggestion is to generate an empty rails 3 project and look at how the generated files and make sure your app looks similar.

Resources