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
66
0
Share
Responders
Dry-out your controllers with some responders
DamirSvrtan
September 14, 2015
More Decks by DamirSvrtan
See All by DamirSvrtan
Designing APIs: Less Data is More
damirsvrtan
1
510
Crossing Domain Boundaries with GraphQL
damirsvrtan
0
190
Surrounded by Microservices
damirsvrtan
2
5.5k
Building Serverless Ruby Bots @ Ruby Conf 2018
damirsvrtan
0
470
Building Serverless Ruby Bots @ Paris.rb Conf 2018
damirsvrtan
1
2.5k
Importing and serving millions of records
damirsvrtan
1
210
Stateless authentication w/ JSON Web Tokens
damirsvrtan
5
360
Building Ruby Bots on AWS Lambda
damirsvrtan
0
1.3k
Reinventing The Bootcamp Idea
damirsvrtan
0
250
Other Decks in Programming
See All in Programming
AI-DLC Deep Dive
yuukiyo
7
1.9k
夢の無限スパゲッティ製造機 -実装篇- #phpstudy
o0h
PRO
0
210
CursorとClaudeCodeとCodexとOpenCodeを実際に比較してみた
terisuke
1
440
Vibe NLP for Applied NLP
inesmontani
PRO
0
390
Exploring RuboCop with MCP
koic
0
370
Go_College_最終発表資料__外部公開用_.pdf
xe_pc23
0
200
Mastering Event Sourcing: Your Parents Holidayed in Yugoslavia
super_marek
0
150
「効かない!」依存性注入(DI)を活用したAPI Platformのエラーハンドリング奮闘記
mkmk884
1
330
Make GenAI Production-Ready with Kubernetes Patterns
bibryam
0
110
RSAが破られる前に知っておきたい 耐量子計算機暗号(PQC)入門 / Intro to PQC: Preparing for the Post-RSA Era
mackey0225
3
130
ハーネスエンジニアリングにどう向き合うか 〜ルールファイルを超えて開発プロセスを設計する〜 / How to approach harness engineering
rkaga
20
8.6k
L’IA au service des devs : Anatomie d'un assistant de Code Review
toham
0
230
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.1k
Six Lessons from altMBA
skipperchong
29
4.2k
Exploring anti-patterns in Rails
aemeredith
3
320
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
510
GitHub's CSS Performance
jonrohan
1032
470k
Speed Design
sergeychernyshev
33
1.6k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.5k
Writing Fast Ruby
sferik
630
63k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
260
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
440
WENDY [Excerpt]
tessaabrams
10
37k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
150
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.