Your SlideShare is downloading. ×
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
What's new in Rails 4.1
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

What's new in Rails 4.1

2,110

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,110
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
11
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. What’s new in 4.1(Chennai.rb March meetup)
  • 2. (@vysakh0) Vysakh Sreenivasan Just want to build cool apps for me and others
  • 3. - Rails app probably take around ~5 seconds to boot. - 50 times a day (test, rails s, rails g...) i.e You waste 5days in a YEAR
  • 4. #1 Spring preloader built in integration in Rails 4.1
  • 5. keeps app running in the background No booting every time you run a test, rake task or migration
  • 6. PARTY IN THOSE 5 DAYS
  • 7. How do you load api keys in Rails? - create .yml, .rb file and load or - figaro gem or - dotenv gem.
  • 8. #2 config/secrets.yml generated by Rails 4.1
  • 9. Just put your api keys in secrets.yml # config/secrets.yml development: facebook_consumer_key: “random skdfjks” facebook_consumer_secret: “its a secret” # config/secrets.yml development: facebook_consumer_key: “random key” facebook_consumer_secret: “its a secret” # config/initializers/devise.rb ….. config.omniauth :facebook, Rails.application.secrets.facebook_consumer_key , Rails. application.secrets.facebook_consumer_secret ….. Just use it like this
  • 10. Config
  • 11. How do you change the state of Order - to pending. - to completed. - to refunded
  • 12. Create separate columns? - completed(:boolean) , refunded(:boolean) Create an integer column? - 0 -> pending - 1 -> completed - 2-> refunded
  • 13. #3 Active Record enums in Rails 4.1
  • 14. # app/modes/order.rb class Order < ActiveRecord::Base # status is an integer column in orders table enum status: { pending: 0, completed: 1, refunded: 2 } end
  • 15. Now enum gives us handy helper methods
  • 16. @order.pending? @order.completed! @order.completed? @order.refunded! @order.refunded?
  • 17. #4 Application Message Verifier built in helper in Rails 4.1
  • 18. irb> @user.id # => 1 irb> user_token = Rails.application.message_verifier (“remember_me”). generate(@user.id) => "BAhpBg==--859750a419640d18d7c24e3166541a9405a42786" irb> get_back_user_id = Rails.application. message_verifier(“remember_me”). verify(user_token) => 1
  • 19. USE CASES - Password reset - Invite links - Oauth tokens - and more
  • 20. Show different templates to phone/browsers/tablets ?
  • 21. #5 Application Pack Variants (Code example taken from http://coherence.io/blog/2013/12/17/whats-new-in-rails-4-1.html )
  • 22. class ApplicationController < ActionController ::Base before_action :detect_device_variant private def detect_device_variant case request.user_agent when /iPad/i request.variant = :tablet when /iPhone/i request.variant = :phone end end end
  • 23. class PostController < ApplicationController def show @post = Post.find(params[:id]) respond_to do |format| format.json format.html # /app/views/posts/show.html.erb format.html.phone # /app/views/posts/show.html+phone.erb format.html.tablet do @show_edit_link = false end end end end
  • 24. #6 Application Mailer Previews
  • 25. class NotifierPreview < ActionMailer::Preview def welcome Notifier.welcome(User.first) end end # test/mailers/notifier_preview.rb
  • 26. List of all mailer previews http://localhost:3000/rails/mailers

×