Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Responders
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
DamirSvrtan
September 14, 2015
Programming
0
59
Responders
Dry-out your controllers with some responders
DamirSvrtan
September 14, 2015
Tweet
Share
More Decks by DamirSvrtan
See All by DamirSvrtan
Designing APIs: Less Data is More
damirsvrtan
1
490
Crossing Domain Boundaries with GraphQL
damirsvrtan
0
180
Surrounded by Microservices
damirsvrtan
2
5.4k
Building Serverless Ruby Bots @ Ruby Conf 2018
damirsvrtan
0
450
Building Serverless Ruby Bots @ Paris.rb Conf 2018
damirsvrtan
1
2.5k
Importing and serving millions of records
damirsvrtan
1
190
Stateless authentication w/ JSON Web Tokens
damirsvrtan
5
350
Building Ruby Bots on AWS Lambda
damirsvrtan
0
1.3k
Reinventing The Bootcamp Idea
damirsvrtan
0
240
Other Decks in Programming
See All in Programming
AIエージェントのキホンから学ぶ「エージェンティックコーディング」実践入門
masahiro_nishimi
5
340
高速開発のためのコード整理術
sutetotanuki
1
390
それ、本当に安全? ファイルアップロードで見落としがちなセキュリティリスクと対策
penpeen
7
2.4k
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
160
「ブロックテーマでは再現できない」は本当か?
inc2734
0
770
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
370
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
130
CSC307 Lecture 09
javiergs
PRO
1
830
組織で育むオブザーバビリティ
ryota_hnk
0
170
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
510
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
150
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
680
Featured
See All Featured
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.1k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
350
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.1k
WCS-LA-2024
lcolladotor
0
450
How to Ace a Technical Interview
jacobian
281
24k
Utilizing Notion as your number one productivity tool
mfonobong
3
220
Leo the Paperboy
mayatellez
4
1.4k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
53
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
For a Future-Friendly Web
brad_frost
182
10k
Between Models and Reality
mayunak
1
180
Speed Design
sergeychernyshev
33
1.5k
Transcript
Responders
©2015 Infinum student academy PostsController#create @post = Post.new(post_params) if @post.save(post_params)
redirect_to @post flash[:notice] = 'Post was successfully updated.' else render :new end
©2015 Infinum student academy What about internationalization?
©2015 Infinum student academy PostsController#create @post = Post.new(post_params) if @post.save
flash[:notice] = I18n.t(‘flash.posts.create.notice’) redirect_to @post else render :new end
©2015 Infinum student academy The update action is very similar
©2015 Infinum student academy PostsController#update @post = Post.find(params[:id]) if @post.update(post_params)
flash[:notice] = I18n.t(‘flash.posts.update.notice’) redirect_to @post else render :edit end
©2015 Infinum student academy The restful controller pseudocode: initialize_resource can
it be saved? flash redirect else render end
Meet the responders..
©2015 Infinum student academy Convenient wrappers for REST controllers @post
= Post.create(post_params) respond_with @post
©2015 Infinum student academy Knows what translation to look at
©2015 Infinum student academy Universal translation for all controllers flash:
actions: create: notice: "%{resource_name} was successfully created." update: notice: "%{resource_name} was successfully updated." destroy: notice: "%{resource_name} was successfully destroyed." alert: "%{resource_name} could not be destroyed."
©2015 Infinum student academy Translation per controller flash: posts: create:
notice: "Your post was created and will be published soon"
©2015 Infinum student academy Need a non-standard redirect location? @post
= Post.create(post_params) respond_with @post, location: -> { posts_path }
©2015 Infinum student academy Need a non-standard rendering template? @post
= Post.create(post_params) respond_with @post, action: ‘shared/posts/new’
History
©2015 Infinum student academy Responders • Extracted from Rails 4.2
to a separate gem • Maintained by Plataformatec • authors of Devise & Simple Form
©2015 Infinum student academy Why were they extracted from Rails?
©2015 Infinum student academy respond_to do |format| format.xml { render
xml: @model } format.json { render json: @model } end is clearer than… respond_with @model
©2015 Infinum student academy I only use them for Html
API’s
Fin.