Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Responders
Search
DamirSvrtan
September 14, 2015
Programming
0
56
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
480
Crossing Domain Boundaries with GraphQL
damirsvrtan
0
170
Surrounded by Microservices
damirsvrtan
2
5.3k
Building Serverless Ruby Bots @ Ruby Conf 2018
damirsvrtan
0
440
Building Serverless Ruby Bots @ Paris.rb Conf 2018
damirsvrtan
1
2.4k
Importing and serving millions of records
damirsvrtan
1
180
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
220
Other Decks in Programming
See All in Programming
dnx で実行できるコマンド、作ってみました
tomohisa
0
130
スタートアップを支える技術戦略と組織づくり
pospome
8
15k
これだけで丸わかり!LangChain v1.0 アップデートまとめ
os1ma
6
1.3k
CloudNative Days Winter 2025: 一週間で作る低レイヤコンテナランタイム
ternbusty
7
1.9k
DSPy Meetup Tokyo #1 - はじめてのDSPy
masahiro_nishimi
1
150
20 years of Symfony, what's next?
fabpot
2
310
レイトレZ世代に捧ぐ、今からレイトレを始めるための小径
ichi_raven
0
490
堅牢なフロントエンドテスト基盤を構築するために行った取り組み
shogo4131
6
1.9k
TypeScriptで設計する 堅牢さとUXを両立した非同期ワークフローの実現
moeka__c
6
2.9k
Full-Cycle Reactivity in Angular: SignalStore mit Signal Forms und Resources
manfredsteyer
PRO
0
180
AIコードレビューがチームの"文脈"を 読めるようになるまで
marutaku
0
310
All(?) About Point Sets
hole
0
260
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Large-scale JavaScript Application Architecture
addyosmani
514
110k
Rebuilding a faster, lazier Slack
samanthasiow
84
9.3k
Agile that works and the tools we love
rasmusluckow
331
21k
Optimising Largest Contentful Paint
csswizardry
37
3.5k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
How to train your dragon (web standard)
notwaldorf
97
6.4k
Documentation Writing (for coders)
carmenintech
76
5.2k
Docker and Python
trallard
46
3.7k
What's in a price? How to price your products and services
michaelherold
246
12k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.3k
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.