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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
DamirSvrtan
September 14, 2015
Programming
0
63
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
500
Crossing Domain Boundaries with GraphQL
damirsvrtan
0
180
Surrounded by Microservices
damirsvrtan
2
5.5k
Building Serverless Ruby Bots @ Ruby Conf 2018
damirsvrtan
0
460
Building Serverless Ruby Bots @ Paris.rb Conf 2018
damirsvrtan
1
2.5k
Importing and serving millions of records
damirsvrtan
1
200
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
atmaCup #23でAIコーディングを活用した話
ml_bear
4
710
浮動小数の比較について
kishikawakatsumi
0
360
メタプログラミングで実現する「コードを仕様にする」仕組み/nikkei-tech-talk43
nikkei_engineer_recruiting
0
130
grapheme_strrev関数が採択されました(あと雑感)
youkidearitai
PRO
1
190
Claude Codeと2つの巻き戻し戦略 / Two Rewind Strategies with Claude Code
fruitriin
0
200
CSC307 Lecture 09
javiergs
PRO
1
850
モジュラモノリスにおける境界をGoのinternalパッケージで守る
magavel
0
3.3k
PJのドキュメントを全部Git管理にしたら、一番喜んだのはAIだった
nanaism
0
220
今更考える「単一責任原則」 / Thinking about the Single Responsibility Principle
tooppoo
3
1.2k
AI活用のコスパを最大化する方法
ochtum
0
120
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
2k
AI時代でも変わらない技術コミュニティの力~10年続く“ゆるい”つながりが生み出す価値
n_takehata
2
540
Featured
See All Featured
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
260
Scaling GitHub
holman
464
140k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
370
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.2k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
750
Documentation Writing (for coders)
carmenintech
77
5.3k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
270
The Curious Case for Waylosing
cassininazir
0
260
Accessibility Awareness
sabderemane
0
71
How to build a perfect <img>
jonoalderson
1
5.2k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
140
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.