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
DamirSvrtan
September 14, 2015
Programming
0
58
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
170
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.4k
Importing and serving millions of records
damirsvrtan
1
190
Stateless authentication w/ JSON Web Tokens
damirsvrtan
5
340
Building Ruby Bots on AWS Lambda
damirsvrtan
0
1.2k
Reinventing The Bootcamp Idea
damirsvrtan
0
230
Other Decks in Programming
See All in Programming
LLM Çağında Backend Olmak: 10 Milyon Prompt'u Milisaniyede Sorgulamak
selcukusta
0
140
ゲームの物理 剛体編
fadis
0
380
令和最新版Android Studioで化石デバイス向けアプリを作る
arkw
0
460
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
400
Navigating Dependency Injection with Metro
l2hyunwoo
1
190
Navigation 3: 적응형 UI를 위한 앱 탐색
fornewid
1
470
実はマルチモーダルだった。ブラウザの組み込みAI🧠でWebの未来を感じてみよう #jsfes #gemini
n0bisuke2
3
1.3k
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
190
SwiftUIで本格音ゲー実装してみた
hypebeans
0
510
リリース時」テストから「デイリー実行」へ!開発マネージャが取り組んだ、レガシー自動テストのモダン化戦略
goataka
0
150
gunshi
kazupon
1
120
Tinkerbellから学ぶ、Podで DHCPをリッスンする手法
tomokon
0
140
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
980
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Reality Check: Gamification 10 Years Later
codingconduct
0
1.9k
A Soul's Torment
seathinner
1
2k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
0
960
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
180
Visualization
eitanlees
150
16k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.4k
How GitHub (no longer) Works
holman
316
140k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
400
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
0
46
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
1
210
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.