Rails 3 rendering is so slow - ruby-on-rails

I recently booted up an old version of a Rails project of mine, which uses Rails 2.3.11 and realized that Rails 2.3 is much faster running almost the same code as the recent version.
My question: Is Rails 3 slower than Rails 2? Especially when rendering lots of partials? The old version never really exceeded 300ms for a request, Rails 3 takes 600ms and more, sometimes even 2 seconds. Any workarounds known? Or should I move my partials into helper methods (generating the html)? And no, downgrading is not an option!
Greetings, Mario

How are you rendering your partials? Rails in development mode can be quite slow. You can try giving this gem a try by adding this to your Gemfile: gem 'rails-dev-boost', :git => 'git://github.com/thedarkone/rails-dev-boost.git', :require => 'rails_development_boost'.
If you are running your partials via a collection, you can always do something like <%= render #posts %> for better performance gains.
Hope this helps!

Related

Rails' client-side-validation form_for error

I am using client validation rails gem and I got this error. Any idea.....
wrong number of arguments (3 for 2)
Extracted source (around line #1):
<%= form_for #user, :validate => true do |f| %>
Trace of template inclusion: app/views/users/new.html.erb
Rails 4 Support
Thanks to tagliala & bcardarella, the client_side_validation gem now supports rails 4!
After adding
gem 'client_side_validations'
to my Gemfile, it didn't load everything properly.
This may be temporarily, as Rubygems only links the old version.
Instead I had to specify the exact repository & branch, since the owner changed.
gem 'client_side_validations', github: "DavyJonesLocker/client_side_validations", branch: "4-2-stable"
Based on https://github.com/bcardarella/client_side_validations/issues/494 it looks like CSV will not support Rails 4 for a little bit longer.
However it also states
I don't see CSV 4.0 coming out for at least 2 months after Rails 4.0 lands (hopefully not that long) as there will be major changes on the JavaScript side of things. Because it will take so longer and people will want a Rails 4.0 compliant version of CSV suggesting they use master branch or perhaps releasing a alpha or pre version to partially satisfy them while we update might be the correct option.
So perhaps try pulling csv right from git? There is a 4.0 beta branch that might be worth trying...
Update
The CSV gem is no longer actively maintained. There are 3 different 4.0 branches on the repository, and the most recently updated of which is 4-0-useable (https://github.com/bcardarella/client_side_validations/branches/all).
Update 2
As #TheChamp says, the CSV gem now supports rails 4.2!
If your using Rails 4 then Client Side validation is outdated. You can check here
http://railscasts.com/episodes/263-client-side-validations?view=comments
and also if you go to the github page
https://github.com/bcardarella/client_side_validations
you can see that it says its no longer maintained.
Alternatively you can try using the CSV gem from this branch, by replacing the CSV line in your Gemfile by this
gem 'client_side_validations', github: "bcardarella/client_side_validations", :branch => "4-0-beta"
Not sure even if this will work though. Since its outdated.
Or you can check this gem out,
https://github.com/kalkov/rails4_client_side_validations
Its just a modified version of Client Side Validations
Have you followed all of the instructions on the github page? If so, have you restarted your server? The install adds an initializer that wont take effect until a server restart.

What should a Rails 3.x noob know about maintaining a Rails 2.3 app?

I recently learned Rails (Rails 3 to be specific) and got a small project maintaining a Rails 2.3.2 app.
So, as you might expect, I keep running into differences between what I learned in Rails 3 and what I'm working in.
For example 'rails server' command in Rails 3 is 'script/server' in Rails 2.x.
What else should I know to maintain my sanity?
If you're new to rails, I don't know if you'll see a lot of differences. The rails server command is one thing however.
The other big thing is the use of .gemspec in Rails 2.3.5 instead of Bundler and Gemfiles in Rails 3. Installing gems/specifying which gems your app uses is way better in Rails 3 I think.
The rest are mostly syntax changes and depreciated functions in specific areas (e.g. javascript generators).
This Blog does a good job of listing most of the major changes in more detail.
Hope that helps!

I have a new Rails 3 app on ruby 1.8.7, what's the impact of moving to 1.9?

I'm newish to rails, and I started with rails 3 and ruby 1.8.7
I'm not sure exactly why I went with 1.8.7, but I think it was because many gems are not supported with 1.9.
Was my analysis wrong and I can move to 1.9?
What are things to consider moving to 1.9? Is rails 3 ready for it?
I've moved to 1.9.2 about two months ago and so far everything seems OK. 1.9 is largely backwards-compatible so most things are not a problem.
That said there are two possible sources of significant annoyance when going to 1.9:
CSV parsing. Ruby switched internally to FasterCSV but doing require 'fastercsv' will result in an error. This will require changes to your code if you are doing any CSV parsing.
Encoding changes. If your code (not data) includes non-ascii characters your app will fall apart. The fix is not hard, you have to put the magic comment # encoding: utf-8 on top of any such files, but again a possible source of pain.
All gems I've been using work fine (except those doing CSV).
The only real way to find out for your application is to use rvm and install 1.9.2. Upgrade all of your gems using Bundler and then run all of your tests. Manual testing of the application will ferret out any remaining issues that are not common and specific to your code and data.

cache_money for Rails 3

I've used various forks (mostly the ngmoco fork) of Nick Kallen's excellent cache_money for several Rails 2.3 based project, but we're now making the leap to Rails 3 which, thanks to the introduction of ActiveRelation, does not work with the popular forks of cache_money.
Is there a fork of cache_money, or an equivalent write-through cache, that is compatible with Rails 3 ?
Last week I launched a new write-through-cache gem for Rails 3, see https://github.com/orslumen/record-cache.
The reason I built it, is because we were using cache money and recently migrated to Rails 3. So chances are it may also serve you well.
There are a branch rails 3 in ngmoco fork to use you :
http://github.com/ngmoco/cache-money/tree/rails3
You can try it I don't know if it's really works.
You can add this in your Gemfile by
gem 'cache_money', :git => 'git://github.com/ngmoco/cache-money.git', :branch => 'rails3'
second_level_cache is also a gem inspired by CacheMoney.

Rails 3 beta 3 -- is it time to start using this for new projects?

Is it time to start new projects in Rails 3? I'm nervous about using beta versions but at the same time I really like what they are doing and don't want to deal with legacy 2.3.5 issues with these apps.
Is it better to wait these things out, or buckle-up, deal with early adopter issues and get a head start on the future. Thanks for any light you can shed.
I'd say no, rails v3.beta3 still has some serious issues that cause it to crash (unexpectedly). As noted from the Riding Rails blog:
Note that Ruby 1.8.7 p248 and p249 has marshaling bugs that crash both Rails 2.3.x and Rails 3.0.0. Ruby 1.9.1 outright segfaults on Rails 3.0.0, so if you want to use Rails 3 with 1.9.x, jump on 1.9.2 trunk for smooth sailing.
Also of note:
Known regressions: Rails crashes unless configuration.action_controller.session is set, config.thread_safe does not work, Unable to run a RJS partial from an HTML template, Backtrace silencers oftem remove application lines from test failures backtraces, Active Record double escapes error_messages_for
I am doing all of my new development work on Rails 3. I have found a couple of issues in general stability, but they are really in the fringe/edge cases - I have a system running on Heroku that is quite stable. The core platform itself is quite stable and the various APIs should not significantly change heading to release.
You need to ask yourself what you've got to lose, but one thing is clear: Rails 2.x is history.

Resources