
Rails 4.1.0 released - chancancode
http://weblog.rubyonrails.org/2014/4/8/Rails-4-1/
======
eggbrain
For those curious as to how things go from Rails 3 to Rails 4.1, I've now
built a few Rails 4 and 4.1 apps for clients and here's been my thoughts:

1) Turbolinks comes standard with Rails 4, and you will either love it or hate
it. If you do use it, expect your javascript to break at one point or another.
The jquery.turbolinks gem helps, but I've still had to debug a bunch of funky
behavior with it.

2) Strong parameters takes a while to get used to from the old
attr_accessesible way of doing things. That being said, I think it's worth it
to learn it. It prevents a lot of conditional attr_accessible :blah, :as =>
:admin that goes on. The one thing I'd say is if you are going to use strong
parameters, you might want to install a gem like Annotate so you can keep
track of your attributes in the models. Sure you can just look in Schema.rb,
but tabbing back and forth gets to be kind of a pain.

3) Secrets.yml is great, no more worrying about adding your
config.secret_token to the .env file when generating every single project.

4) Mail Preview is nice, but for some reason I still seem to use Mailcatcher
mostly to view / see how emails render out. Think this is mostly me sticking
to my own ways.

5) ActionController::Live still feels pretty half baked. The fact that most
examples / tutorials on the web still use the default example of:

    
    
        100.times {
          response.stream.write "hello world\n"
          sleep 1
        }
    

Seems quite telling. It feels like they've given some of the pieces to get
live streaming working flawlessly, but we are still missing a few tools here.

\----

The biggest problem I've had is that some gems that we used frequently would
break because they weren't Rails 4 ready. We use ActiveAdmin pretty frequently
in our client apps, and it's worked for a while, but it's always been on a
custom branch and still had some issues that were just recently fixed. YMMV
for gems that your app relies on in terms of what will break and what will
work.

~~~
subsection1h
> _Secrets.yml is great_

Yes, but I still prefer Figaro[1], which makes it super easy to configure an
app on Heroku, especially when the app has multiple environments on Heroku:

    
    
        $ rake figaro:heroku[my-app-staging]
        $ rake figaro:heroku[my-app-production]
    

[1]
[https://github.com/laserlemon/figaro](https://github.com/laserlemon/figaro)

~~~
stiff
I never understood why you would use YAML for storing settings. In fact, I
observed that because of YAML devs are less likely to extract things into
configuration settings, especially adding a setting seems to involve a manual
server restart. I wrote a gem that's IMO much better:

[https://github.com/jaroslawr/dynamic_configuration](https://github.com/jaroslawr/dynamic_configuration)

Settings are configured in Ruby, split into separate files/groups, are easily
overwritten per-Rails-env and per-particular-installation, in development
environment they are reloaded automatically after a setting is added etc.

~~~
dasil003
I think it's largely a case of cargo-culting a Rails core decision made
somewhat arbitrarily before Rails was even released (ie. config/database.yml).

Theoretically I suppose YAML is supposed to be a human-editable data format,
but after trying to get translators to translate app strings in YAML format I
decided that YAML is worthless as anything except an interchange format, and
even there, primarily for Ruby because of its rich semantics.

------
quaunaut
The Enum implementation seems full of caveats.

1\. It saves values as integers in the database, meaning that removing
properties involves explicit setting, and reordering them requires custom
migration code.

2\. "Avoid using the same names inside different enums in the same class!
Doing so will leave Active Record very confused!"[1]

That's right, we can't use the same enum name to two different fields _because
ActiveRecord might get confused_. That's kind of poor, isn't it?

3\. Having to pass a macro that'll return the right integer instead of the
symbol itself? Really?

This all seems _really_ unwieldy, especially in the face of
Enumerize([https://github.com/brainspec/enumerize](https://github.com/brainspec/enumerize)).
It's got none of these caveats. Is there some strength to the Rails enums that
Enumerize doesn't capitalize on, other than size constraints by using Int
instead of String?

[1] [http://brewhouse.io/blog/2013/12/17/whats-new-in-
rails-4-1.h...](http://brewhouse.io/blog/2013/12/17/whats-new-in-
rails-4-1.html)

~~~
izietto
Yes it's disappointing, above all considering that a better implementation is
achievable in twenty lines of code in a model

------
losvedir
My company is still on Rails 3.2. We had been waiting for the first minor
release of Rails 4 to give folks a chance to work out issues, so maybe now
it's time to look at upgrading.

Anyone have major issues going from 3.2 -> 4? I've heard horror stories about
2 -> 3, but I didn't pick up Rails myself until 3.x so I don't have firsthand
experience.

The biggest change I see is attr_accessible to strong_parameters. Does that
mean I need to go through and rewrite all our models and controllers before we
can update?

~~~
patrickdavey
The railsdiff website is also a very handy little tool for quickly seeing the
differences in config between versions:

[http://railsdiff.org/diff/v3.2.17/v4.1.0/](http://railsdiff.org/diff/v3.2.17/v4.1.0/)

~~~
harrylove
[https://github.com/rails/rails/compare/v4.1.0...v3.2.17](https://github.com/rails/rails/compare/v4.1.0...v3.2.17)

~~~
timdorr
Railsdiff.org just shows you what's changed in the generated app files, not
the actual libraries.

------
recursive
I don't have much to say about any of the new functionality, but Spring seems
like a very poor name for anything new related to programming.

~~~
mountaineer
I agree with you, Spring is already well known in Java circles (and .NET to
some extent).

~~~
iagooar
And that's why it doesn't matter _at all_ in the Ruby / Rails community ;)

~~~
danielweber
And a nightmare for people in both the Java and Rails community when seeking
jobs.

------
callmeed
Having mailer previews built in is pretty awesome. I pretty much use a gem for
that on every project nowadays.

The variants thing is interesting ... I'm assuming its an alternative to
rendering a responsive/mobile-first view (on a view-by-view basis). I'm sure
there are plenty of use-cases but I don't like the prospect of having to
update yet-another-set-of-layouts-and-views.

~~~
dhh
Responsive views only go so far. Trying to shrink an app designed for a
desktop browser down to a 4" phone is a fool's errand. Much easier to go with
different templates in that case.

~~~
oelmekki
> Trying to shrink an app designed for a desktop browser down to a 4" phone is
> a fool's errand

That's why, when you design a responsive website, you're supposed to think /
work out mobile first.

Hoping to detect all mobile devices out there based on their http request is
no wiser.

~~~
sergiotapia
You end up with a LOT of hidden or visible markup, redundant on both mobile
and desktop.

After working on responsive websites for about 2 years now, I feel that
variants is the way to go with Mobile designs.

You flesh out something lightweight for mobile and then another for tablet +
desktop + whatever.

Otherwise your mobile display is needlessly large.

------
matthewmacleod
Upgrading from 4.0 to 4.1

    
    
      1013 runs, 351 assertions, 6 failures, 832 errors, 0 skips
    

Ouch. Still, it's great to see development on Rails continue. It really hits a
great sweet spot for small to mid-sized apps.

Edit: Actually easier than I thought; about 10 minutes to figure out the cause
and remove a surplus gem, and we're all green. Cool.

~~~
gargarplex
What is great for large-sized apps?

~~~
matthewmacleod
Interesting and complex question, that.

Larger apps end up being more SOA than monolithic, I suppose. Rails can
usually play a part in these, but in my experience it's usually a win to start
fragmenting an app into services once it gets beyond a certain size and
complexity.

------
simple10
We've been using Rails 4.1 release candidates for a couple of projects. It's
worth the upgrade from 3.2.

Here's a Rails 4.1.0 starter kit that's production ready and full featured:
[https://github.com/starterkits/rails4-starterkit](https://github.com/starterkits/rails4-starterkit)

~~~
ch4s3
This looks pretty nice, but do people actually use these for production apps?
I'm not criticising, I'm legitimately curious .

~~~
jrochkind1
I never heard of it before, and the url is timing out for me now (I was gonna
say HN effect, but that's a github.com, uh oh. Anyway).

I thought the Rails 'starter kit' was `rails new my_app_name`

~~~
ch4s3
Interesting, I looked through it, and his other repos, and he seems to be a
really solid rails guy. Looks like a promising kit, especially considering how
much of a pita setting up CanCan with Rails 4 can be.

~~~
simple10
Thanks ch4s3. I released the starter kit after bashing my head in on a few
configuration tasks with various gems. I haven't looked far and wide, but I
think it's one of the more complete Rails 4 starter apps. I needed it for my
own projects, but hopefully it can save some other devs configuration time.

If you know of other solid starter app projects, I'm happy to fork them and
make them discoverable in
[https://github.com/starterkits](https://github.com/starterkits). It's meant
to be a community project. I just haven't had any time to promote it.

~~~
midas007
Neat. The problem with templates in general they lose an ability to hack on
and recreate them because they depend on code generation and manual tweaks
that have already been done (and lost). As such, I'm refactoring
[https://github.com/steakknife/rails41rc_plus_hacks_and_threa...](https://github.com/steakknife/rails41rc_plus_hacks_and_threads)
into generators that will add the right things to a bare Rails app. So if you
need omniauth + devise + cancan but not X, it's a `rails g` away. Rails has an
amazing app generator DSL built-in.

~~~
simple10
I totally agree. Generators are the way to go. I just haven't had time to make
them for starterkit.

Open an issue or pull request when you get your generators working, and I'll
happily link to your project. Always good to give people options.

------
DanielKehoe
I've updated the ‘Learn Ruby on Rails’ book for Rails 4.1:

[http://learn-rails.com/learn-ruby-on-rails.html](http://learn-
rails.com/learn-ruby-on-rails.html)

Also, there are 5 starter apps for Rails 4.1 from Rails Composer:

[http://blog.railsapps.org/post/79115273530/5-starter-apps-
fo...](http://blog.railsapps.org/post/79115273530/5-starter-apps-for-
rails-4-1-from-rails-composer)

------
joevandyk
You'd think the new enum support could use.. you know.. ENUMS.
[http://www.postgresql.org/docs/9.3/static/datatype-
enum.html](http://www.postgresql.org/docs/9.3/static/datatype-enum.html)

~~~
xs_kid
the rails team is waiting for a patch to do it

~~~
rimantas
With support for databases not supporting enums.

------
Podeau
More info on Secrets.yml VS Figaro here
[http://collectiveidea.com/blog/archives/2013/12/18/the-
marri...](http://collectiveidea.com/blog/archives/2013/12/18/the-marriage-of-
figaro-and-rails/)

------
desireco42
The only thing I noticed, aside from secrets file and cookies etc that is
outline in the notes, is that SimpleForm stopped working. Since project I was
upgrading was small, I just removed it, but that is not option for bigger
projects.

------
sergiotapia
I am _stupidly_ excited for Variants. No more .hidden-xs, visible-xs markup
for me. I can taste the savings! :D

A massive thank you to the Rails team for their time and commitment towards
making the best web framework on the web even better!

------
karmajunkie
Am I the only one who thinks the `Module.concerning` thing is silly?

Concerns never did anything for reducing real complexity in the first place,
except improve code geography, and now we don't even have to bother with that.
Yay.

------
abvdasker
Mailer previews will literally shave hours of time off of my email testing
workflow — no more mail-to-a-test-account-and-wait garbage. And that's one of
the minor features.

~~~
thenduks
letter_opener[1] is really useful to avoid the test account + wait situation.
Well, now you can just use mailer previews, I guess :)

[1]:
[https://github.com/ryanb/letter_opener](https://github.com/ryanb/letter_opener)

~~~
matthewmacleod
Also Mailcatcher, which runs a local SMTP server with a nice email-client-
style web UI: [http://mailcatcher.me](http://mailcatcher.me)

------
NicoJuicy
Is SQLLite fixed for Windows 7 or Windows 8 x64? This was the reason why i
uninstalled Rails 4...

