Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Responders
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
DamirSvrtan
September 14, 2015
Programming
78
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Responders
Dry-out your controllers with some responders
DamirSvrtan
September 14, 2015
Transcript
20 slides
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.
More Decks by DamirSvrtan
See All by DamirSvrtan
Designing APIs: Less Data is More
damirsvrtan
1
580
Crossing Domain Boundaries with GraphQL
damirsvrtan
0
230
Surrounded by Microservices
damirsvrtan
2
5.6k
Building Serverless Ruby Bots @ Ruby Conf 2018
damirsvrtan
0
510
Building Serverless Ruby Bots @ Paris.rb Conf 2018
damirsvrtan
1
2.6k
Importing and serving millions of records
damirsvrtan
1
250
Stateless authentication w/ JSON Web Tokens
damirsvrtan
5
410
Building Ruby Bots on AWS Lambda
damirsvrtan
0
1.3k
Reinventing The Bootcamp Idea
damirsvrtan
0
310
Other Decks in Programming
See All in Programming
はじめてのPLATEAU
nokonoko1203
1
660
AIが生成したコードは読むべきか?抽象化設計とコードの品質保証 / abstraction-design-and-quality
minodriven
16
9.3k
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
140
オーケストレーション記述言語 Katari
yukikurage
0
270
Vapor Mode でアクセシビリティは 壊れないか検証した話
fuqda
1
350
AI駆動開発4年目の現在地(『あなたはFDEになるべきか?』イベント資料)
kumaiu
0
650
baseline으로 마이그레이션, 리팩토링 안전하게 맡기기
fornewid
1
1k
SODA - FACT BOOK(JP)
sodainc
1
40k
作れるエンジニアから、価値を届けるエンジニアへ
ryunakayama
1
300
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
320
Zero-Tap Sign-In対応、結局何をすればいいの?
mitohato14
0
2.3k
Kotlin JVM用に作られたライブラリのKMPを前提とした再設計
jsoizo
0
130
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.8k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
350
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
550
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.9k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
4 Signs Your Business is Dying
shpigford
187
23k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
520
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.9k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
600
Crafting Experiences
bethany
1
440
Building the Perfect Custom Keyboard
takai
2
960