Rails 4.1 is coming out soon and I'd like to summarize which new features I like the most.
Spring Application Preloader
Spring preloads your application which makes your test runs a lot faster. Rails 4.1 generates the binstubs with spring so when you call `rails` or `rake` spring will handle the call. If you want to run a command without spring you can do so by using `bundle rails` or `bundle rake`.
Another change I'd like to mention here is two new rake task to run the tests:
rake test:all
rake test:all:db
The first command merges your different types of test(model, controller, integration, mailer) and runs them. It also does not reset your db so your tests should run faster. The second one does the same except it resets the db between the test.
config/secrets.yml
You may have used [figaro](https://github.com/laserlemon/figaro) before to keep the sensitive data out of your repo but from now on Rails provides a built-in solution to this problem. Rails 4.1 generates a secret.yml in the config folder and you can store api keys, etc in it. The syntax as follows:
If you want to access these in your application you can do so by calling `Rails.application.secrets.some_api_key`.
Action Pack Variants
Mobiles and Tablets are widely used these days and from Rails 4.1 we can easily separate the templates for the different clients. You need to set the variant in your controller:
caserequest.user_agentwhen/iPad/request.variant=:tabletwhen/iPhone|Android/# far from complete. just for the sake of examplerequest.variant=:phoneend
And in your `respond_to` block you can render a separate view:
With this extension to ActiceRecord you can declare an enum field in your model and Rails will handle the mapping of integer values in the database column to human friendly values in your code.
conversation.active?# to see if the record is activeconversation.active!# to set the record active
It also makes easy to implement a simple state machine.
I am already using this feature in production and it works like a charm.
CSRF protection from remote `script` tags
I use RJS to update parts of the applications via ajax and as homakov pointed out in the past this was vulnerable to CSRF. To fix the security issue Rails will use CSRF protection if the request is not xhr.
Added Numeric#in_milliseconds
In the past I always wrote `x * 1000` to convert timestamps I used on the client-side but now this is handled by this syntax sugar.
These are the changes I like the most but you can find an exhaustive list of changes in the changelog, thanks to Yves and Godfrey.
Did you enjoy reading this?Sign up to the Rails Tricks newsletter for more content like this!