The document discusses how Rails routes incoming requests. The router maps URLs to controller actions. It does this by matching routes in order from top to bottom. Resource routing is the modern style and maps HTTP verbs to actions. Named routes can be used for special cases or pretty URLs. Singleton resources handle unique per user resources like sessions. The router ensures each request is routed to the proper controller and action.
Slides from a presentation given at Laravel Chicago on November 18, 2014. Goes over the basics of building a REST API using the Laravel framework as well as some handy tips and tools.
This presentation is part of the Clojure Workshop training offered by Sytac. Learn how to create Web Applications and Rest APIs with the simple abstractions provided by the Clojure language and ecosystem.
Slides from a presentation given at Laravel Chicago on November 18, 2014. Goes over the basics of building a REST API using the Laravel framework as well as some handy tips and tools.
This presentation is part of the Clojure Workshop training offered by Sytac. Learn how to create Web Applications and Rest APIs with the simple abstractions provided by the Clojure language and ecosystem.
Unlocking Productivity: Leveraging the Potential of Copilot in Microsoft 365, a presentation by Christoforos Vlachos, Senior Solutions Manager – Modern Workplace, Uni Systems
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
In his public lecture, Christian Timmerer provides insights into the fascinating history of video streaming, starting from its humble beginnings before YouTube to the groundbreaking technologies that now dominate platforms like Netflix and ORF ON. Timmerer also presents provocative contributions of his own that have significantly influenced the industry. He concludes by looking at future challenges and invites the audience to join in a discussion.
A tale of scale & speed: How the US Navy is enabling software delivery from l...sonjaschweigert1
Rapid and secure feature delivery is a goal across every application team and every branch of the DoD. The Navy’s DevSecOps platform, Party Barge, has achieved:
- Reduction in onboarding time from 5 weeks to 1 day
- Improved developer experience and productivity through actionable findings and reduction of false positives
- Maintenance of superior security standards and inherent policy enforcement with Authorization to Operate (ATO)
Development teams can ship efficiently and ensure applications are cyber ready for Navy Authorizing Officials (AOs). In this webinar, Sigma Defense and Anchore will give attendees a look behind the scenes and demo secure pipeline automation and security artifacts that speed up application ATO and time to production.
We will cover:
- How to remove silos in DevSecOps
- How to build efficient development pipeline roles and component templates
- How to deliver security artifacts that matter for ATO’s (SBOMs, vulnerability reports, and policy evidence)
- How to streamline operations with automated policy checks on container images
GridMate - End to end testing is a critical piece to ensure quality and avoid...ThomasParaiso2
End to end testing is a critical piece to ensure quality and avoid regressions. In this session, we share our journey building an E2E testing pipeline for GridMate components (LWC and Aura) using Cypress, JSForce, FakerJS…
Removing Uninteresting Bytes in Software FuzzingAftab Hussain
Imagine a world where software fuzzing, the process of mutating bytes in test seeds to uncover hidden and erroneous program behaviors, becomes faster and more effective. A lot depends on the initial seeds, which can significantly dictate the trajectory of a fuzzing campaign, particularly in terms of how long it takes to uncover interesting behaviour in your code. We introduce DIAR, a technique designed to speedup fuzzing campaigns by pinpointing and eliminating those uninteresting bytes in the seeds. Picture this: instead of wasting valuable resources on meaningless mutations in large, bloated seeds, DIAR removes the unnecessary bytes, streamlining the entire process.
In this work, we equipped AFL, a popular fuzzer, with DIAR and examined two critical Linux libraries -- Libxml's xmllint, a tool for parsing xml documents, and Binutil's readelf, an essential debugging and security analysis command-line tool used to display detailed information about ELF (Executable and Linkable Format). Our preliminary results show that AFL+DIAR does not only discover new paths more quickly but also achieves higher coverage overall. This work thus showcases how starting with lean and optimized seeds can lead to faster, more comprehensive fuzzing campaigns -- and DIAR helps you find such seeds.
- These are slides of the talk given at IEEE International Conference on Software Testing Verification and Validation Workshop, ICSTW 2022.
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
In this presentation, we examine the challenges and limitations of relying too heavily on PHP frameworks in web development. We discuss the history of PHP and its frameworks to understand how this dependence has evolved. The focus will be on providing concrete tips and strategies to reduce reliance on these frameworks, based on real-world examples and practical considerations. The goal is to equip developers with the skills and knowledge to create more flexible and future-proof web applications. We'll explore the importance of maintaining autonomy in a rapidly changing tech landscape and how to make informed decisions in PHP development.
This talk is aimed at encouraging a more independent approach to using PHP frameworks, moving towards a more flexible and future-proof approach to PHP development.
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
Dr. Sean Tan, Head of Data Science, Changi Airport Group
Discover how Changi Airport Group (CAG) leverages graph technologies and generative AI to revolutionize their search capabilities. This session delves into the unique search needs of CAG’s diverse passengers and customers, showcasing how graph data structures enhance the accuracy and relevance of AI-generated search results, mitigating the risk of “hallucinations” and improving the overall customer journey.
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
Pushing the limits of ePRTC: 100ns holdover for 100 daysAdtran
At WSTS 2024, Alon Stern explored the topic of parametric holdover and explained how recent research findings can be implemented in real-world PNT networks to achieve 100 nanoseconds of accuracy for up to 100 days.
Threats to mobile devices are more prevalent and increasing in scope and complexity. Users of mobile devices desire to take full advantage of the features
available on those devices, but many of the features provide convenience and capability but sacrifice security. This best practices guide outlines steps the users can take to better protect personal devices and information.
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionAggregage
Join Maher Hanafi, VP of Engineering at Betterworks, in this new session where he'll share a practical framework to transform Gen AI prototypes into impactful products! He'll delve into the complexities of data collection and management, model selection and optimization, and ensuring security, scalability, and responsible use.
4. The Router’s Job
Each time a request comes in, Rails needs to send it to
some action in some controller
5. The Router’s Job
Each time a request comes in, Rails needs to send it to
some action in some controller
That’s what the router does
6. The Router’s Job
Each time a request comes in, Rails needs to send it to
some action in some controller
That’s what the router does
The router primarily maps URL’s to actions
7. The Router’s Job
Each time a request comes in, Rails needs to send it to
some action in some controller
That’s what the router does
The router primarily maps URL’s to actions
It may also route based on HTTP verbs
8. The Router’s Job
Each time a request comes in, Rails needs to send it to
some action in some controller
That’s what the router does
The router primarily maps URL’s to actions
It may also route based on HTTP verbs
It can be made to route on additional criteria, like
host name
16. The Default Routes
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
17. The Default Routes
map.connect ':controller/:action/:id'
These rules support an map.connect ':controller/:action/:id.:format'
older style of Rail
routing
/prompts
/prompts/new
/prompts/create
/prompts/show/1
/prompts/edit/1
/prompts/update/1
/prompts/destroy/1
18. The Default Routes
map.connect ':controller/:action/:id'
These rules support an map.connect ':controller/:action/:id.:format'
older style of Rail
routing
It has fallen out of /prompts
/prompts/new
fashion /prompts/create
/prompts/show/1
/prompts/edit/1
/prompts/update/1
/prompts/destroy/1
19. The Default Routes
map.connect ':controller/:action/:id'
These rules support an map.connect ':controller/:action/:id.:format'
older style of Rail
routing
It has fallen out of /prompts
/prompts/new
fashion /prompts/create
/prompts/show/1
Some people now /prompts/edit/1
/prompts/update/1
remove these rules /prompts/destroy/1
21. Route Priority
Routes are matches matched in top to bottom order as
they appear in the routes file
22. Route Priority
Routes are matches matched in top to bottom order as
they appear in the routes file
The first route to match an incoming request wins
23. Route Priority
Routes are matches matched in top to bottom order as
they appear in the routes file
The first route to match an incoming request wins
Lower routes may never fire, if a higher route hides
them by matching requests
24. Route Priority
Routes are matches matched in top to bottom order as
they appear in the routes file
The first route to match an incoming request wins
Lower routes may never fire, if a higher route hides
them by matching requests
This is why the default routes are at the bottom of the
file: they are the last resort
27. Resource Routing
This is the modern map.resources :prompts
Rails routing style map.resources :submissions
map.resources :users
GET /prompts
GET /prompts/new
POST /prompts
GET /prompts/1
GET /prompts/1/edit
PUT /prompts/1
DELETE /prompts/1
28. Resource Routing
This is the modern map.resources :prompts
Rails routing style map.resources :submissions
map.resources :users
You can add non-
standard actions
GET /prompts
GET /prompts/new
POST /prompts
GET /prompts/1
GET /prompts/1/edit
PUT /prompts/1
DELETE /prompts/1
29. Resource Routing
This is the modern map.resources :prompts
Rails routing style map.resources :submissions
map.resources :users
You can add non-
standard actions
GET /prompts
It routes based on GET /prompts/new
HTTP verbs POST /prompts
GET /prompts/1
GET /prompts/1/edit
PUT /prompts/1
DELETE /prompts/1
30. Resource Routing
This is the modern map.resources :prompts
Rails routing style map.resources :submissions
map.resources :users
You can add non-
standard actions
GET /prompts
It routes based on GET /prompts/new
HTTP verbs POST /prompts
GET /prompts/1
GET /prompts/1/edit
You get named path/url PUT /prompts/1
DELETE /prompts/1
methods for free
32. What are HTTP Verbs?
The Web’s transport protocol understands a powerful
language of verbs and objects
33. What are HTTP Verbs?
The Web’s transport protocol understands a powerful
language of verbs and objects
Browser’s are generally dumb and do not
34. What are HTTP Verbs?
The Web’s transport protocol understands a powerful
language of verbs and objects
Browser’s are generally dumb and do not
They use only GET (links) and POST (forms)
35. What are HTTP Verbs?
The Web’s transport protocol understands a powerful
language of verbs and objects
Browser’s are generally dumb and do not
They use only GET (links) and POST (forms)
Rails fakes it with browsers using hidden parameters
36. What are HTTP Verbs?
The Web’s transport protocol understands a powerful
language of verbs and objects
Browser’s are generally dumb and do not
They use only GET (links) and POST (forms)
Rails fakes it with browsers using hidden parameters
It also supports the real verbs from smart agents
37. What are HTTP Verbs?
The Web’s transport protocol understands a powerful
language of verbs and objects
Browser’s are generally dumb and do not
They use only GET (links) and POST (forms)
Rails fakes it with browsers using hidden parameters
It also supports the real verbs from smart agents
This is very nice when building API’s
47. Resource Path Methods
new_user_path() user_path(user)
GET for new GET for show
edit_user_path()
GET for edit
users_path()
GET for index
POST for create
48. Resource Path Methods
new_user_path() user_path(user)
GET for new GET for show
edit_user_path() PUT for update
GET for edit
users_path()
GET for index
POST for create
49. Resource Path Methods
new_user_path() user_path(user)
GET for new GET for show
edit_user_path() PUT for update
GET for edit DELETE for destroy
users_path()
GET for index
POST for create
52. Singleton Resources
A special case of map.resource :user_session
resource routing
GET /user_session/new
POST /user_session
GET /user_session
GET /user_session/edit
PUT /user_session
DELETE /user_session
new_user_session_path
edit_user_session_path
user_session_path
53. Singleton Resources
A special case of map.resource :user_session
resource routing
GET /user_session/new
For unique to the user POST /user_session
GET /user_session
resources GET /user_session/edit
PUT /user_session
DELETE /user_session
new_user_session_path
edit_user_session_path
user_session_path
54. Singleton Resources
A special case of map.resource :user_session
resource routing
GET /user_session/new
For unique to the user POST /user_session
GET /user_session
resources GET /user_session/edit
PUT /user_session
DELETE /user_session
Logins
new_user_session_path
edit_user_session_path
user_session_path
55. Singleton Resources
A special case of map.resource :user_session
resource routing
GET /user_session/new
For unique to the user POST /user_session
GET /user_session
resources GET /user_session/edit
PUT /user_session
DELETE /user_session
Logins
The user’s account new_user_session_path
edit_user_session_path
user_session_path
56. Singleton Resources
A special case of map.resource :user_session
resource routing
GET /user_session/new
For unique to the user POST /user_session
GET /user_session
resources GET /user_session/edit
PUT /user_session
DELETE /user_session
Logins
The user’s account new_user_session_path
edit_user_session_path
user_session_path
…
59. Named Routes
Best for special cases and map.login "login",
:controller => "user_sessions",
pretty URL’s :action => "new"
map.logout "logout",
:controller => "user_sessions",
:action => "destroy"
map.activate "activate/:token",
:controller => "activations",
:action => "create"
60. Named Routes
Best for special cases and map.login "login",
:controller => "user_sessions",
pretty URL’s :action => "new"
map.logout "logout",
:controller => "user_sessions",
:action => "destroy"
map.activate "activate/:token",
:controller => "activations",
:action => "create"
61. Named Routes
Best for special cases and map.login "login",
:controller => "user_sessions",
pretty URL’s :action => "new"
map.logout "logout",
:controller => "user_sessions",
:action => "destroy"
map.activate "activate/:token",
:controller => "activations",
:action => "create"
62. Named Routes
Best for special cases and map.login "login",
:controller => "user_sessions",
pretty URL’s :action => "new"
map.logout "logout",
:controller => "user_sessions",
:action => "destroy"
login_path is preferred to map.activate "activate/:token",
new_user_session_path :controller => "activations",
:action => "create"
/login
/logout
/activate/5HkeFFwiInKfjA4x25q9
63. Named Routes
Best for special cases and map.login "login",
:controller => "user_sessions",
pretty URL’s :action => "new"
map.logout "logout",
:controller => "user_sessions",
:action => "destroy"
login_path is preferred to map.activate "activate/:token",
new_user_session_path :controller => "activations",
:action => "create"
Email links must GET
/login
/logout
/activate/5HkeFFwiInKfjA4x25q9
64. Named Routes
Best for special cases and map.login "login",
:controller => "user_sessions",
pretty URL’s :action => "new"
map.logout "logout",
:controller => "user_sessions",
:action => "destroy"
login_path is preferred to map.activate "activate/:token",
new_user_session_path :controller => "activations",
:action => "create"
Email links must GET
/login
/logout
You can choose to create
the path method /activate/5HkeFFwiInKfjA4x25q9
66. Example: A Sign-up Route
We could add a sign-
up route
map.signup "signup",
:controller => "users",
:action => "new"
67. Example: A Sign-up Route
We could add a sign-
up route
This would allow us
to use signup_path map.signup "signup",
instead of :controller => "users",
:action => "new"
new_user_path
68. Example: A Sign-up Route
We could add a sign-
up route
This would allow us
to use signup_path map.signup "signup",
instead of :controller => "users",
:action => "new"
new_user_path
That would route
to /signup instead
of /users/new
71. The Root Path
Set this path to the
landing page map.root :controller => "prompts",
:action => "index"
http://localhost:3000/
http://myapp.com/
72. The Root Path
Set this path to the
landing page map.root :controller => "prompts",
:action => "index"
You have to remove
public/index.html to
get it to work
http://localhost:3000/
http://myapp.com/
73. The Root Path
Set this path to the
landing page map.root :controller => "prompts",
:action => "index"
You have to remove
public/index.html to
get it to work
http://localhost:3000/
http://myapp.com/
This does create a
root_path() method
75. prompts GET /prompts(.:format) {:action=>"index", :controller=>"prompts"}
POST /prompts(.:format) {:action=>"create", :controller=>"prompts"}
new_prompt GET /prompts/new(.:format) {:action=>"new", :controller=>"prompts"}
edit_prompt GET /prompts/:id/edit(.:format) {:action=>"edit", :controller=>"prompts"}
prompt GET /prompts/:id(.:format) {:action=>"show", :controller=>"prompts"}
PUT /prompts/:id(.:format) {:action=>"update", :controller=>"prompts"}
DELETE /prompts/:id(.:format) {:action=>"destroy", :controller=>"prompts"}
submissions GET /submissions(.:format) {:action=>"index", :controller=>"submissions"}
POST /submissions(.:format) {:action=>"create", :controller=>"submissions"}
new_submission GET /submissions/new(.:format) {:action=>"new", :controller=>"submissions"}
edit_submission GET /submissions/:id/edit(.:format) {:action=>"edit", :controller=>"submissions"}
submission GET /submissions/:id(.:format) {:action=>"show", :controller=>"submissions"}
PUT /submissions/:id(.:format) {:action=>"update", :controller=>"submissions"}
DELETE /submissions/:id(.:format) {:action=>"destroy", :controller=>"submissions"}
users GET /users(.:format) {:action=>"index", :controller=>"users"}
POST /users(.:format) {:action=>"create", :controller=>"users"}
new_user GET /users/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}
new_user_session GET /user_session/new(.:format) {:action=>"new", :controller=>"user_sessions"}
edit_user_session GET /user_session/edit(.:format) {:action=>"edit", :controller=>"user_sessions"}
user_session GET /user_session(.:format) {:action=>"show", :controller=>"user_sessions"}
PUT /user_session(.:format) {:action=>"update", :controller=>"user_sessions"}
DELETE /user_session(.:format) {:action=>"destroy", :controller=>"user_sessions"}
POST /user_session(.:format) {:action=>"create", :controller=>"user_sessions"}
login /login {:action=>"new", :controller=>"user_sessions"}
logout /logout {:action=>"destroy", :controller=>"user_sessions"}
rake routes
This command shows all of the routes
currently set for your application
77. There’s More to the Router!
You can add “collection” or “member” actions to the
seven standard resource routes
78. There’s More to the Router!
You can add “collection” or “member” actions to the
seven standard resource routes
You can nest resources
79. There’s More to the Router!
You can add “collection” or “member” actions to the
seven standard resource routes
You can nest resources
Creating routes like: /prompts/1/submissions/1
80. There’s More to the Router!
You can add “collection” or “member” actions to the
seven standard resource routes
You can nest resources
Creating routes like: /prompts/1/submissions/1
You can prefix routes
81. There’s More to the Router!
You can add “collection” or “member” actions to the
seven standard resource routes
You can nest resources
Creating routes like: /prompts/1/submissions/1
You can prefix routes
Creating routes like: /admin/users/1
82. There’s More to the Router!
You can add “collection” or “member” actions to the
seven standard resource routes
You can nest resources
Creating routes like: /prompts/1/submissions/1
You can prefix routes
Creating routes like: /admin/users/1
…
85. What is Rendered?
If an action doesn’t call redirect_to() at some point,
some kind of render() generally takes place
86. What is Rendered?
If an action doesn’t call redirect_to() at some point,
some kind of render() generally takes place
If render() is called, Rails will try to satisfy that request
87. What is Rendered?
If an action doesn’t call redirect_to() at some point,
some kind of render() generally takes place
If render() is called, Rails will try to satisfy that request
Otherwise a default render happens
88. What is Rendered?
If an action doesn’t call redirect_to() at some point,
some kind of render() generally takes place
If render() is called, Rails will try to satisfy that request
Otherwise a default render happens
Rails will hunt for a view named for the current action
89. What is Rendered?
If an action doesn’t call redirect_to() at some point,
some kind of render() generally takes place
If render() is called, Rails will try to satisfy that request
Otherwise a default render happens
Rails will hunt for a view named for the current action
Rails will try to honor the requested format
91. The Render Format
Both resource routes and the default routes include an
optional :format parameter
92. The Render Format
Both resource routes and the default routes include an
optional :format parameter
This allows you to visit a URL like: /users/1.json
93. The Render Format
Both resource routes and the default routes include an
optional :format parameter
This allows you to visit a URL like: /users/1.json
The requested :format there is JSON instead of the
default HTML
94. The Render Format
Both resource routes and the default routes include an
optional :format parameter
This allows you to visit a URL like: /users/1.json
The requested :format there is JSON instead of the
default HTML
Rails also honors the HTTP Accept header
96. Responding to Formats
def index
@articles = Article.all
respond_to do |format|
format.html # take the default action
format.xml do
render :xml => @articles.to_xml
end
format.json do
render :json => @articles.to_json
end
end
end
97. Responding to Formats
You can use
respond_to to set def index
@articles = Article.all
explicit responses for respond_to do |format|
format.html # take the default action
each format format.xml do
render :xml => @articles.to_xml
end
format.json do
render :json => @articles.to_json
end
end
end
98. Responding to Formats
You can use
respond_to to set def index
@articles = Article.all
explicit responses for respond_to do |format|
format.html # take the default action
each format format.xml do
render :xml => @articles.to_xml
end
format.json do
render :json => @articles.to_json
end
end
end
99. Responding to Formats
You can use
respond_to to set def index
@articles = Article.all
explicit responses for respond_to do |format|
format.html # take the default action
each format format.xml do
render :xml => @articles.to_xml
end
format.json do
ActiveRecord knows render :json => @articles.to_json
end
how to write XML and end
end
JSON
100. The Accept Header
Note how the responses changed as I modified
the header but hit the URL
101. $ curl http://localhost:3000/articles
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
…
$ curl -H 'Accept: application/xml' http://localhost:3000/articles
<?xml version="1.0" encoding="UTF-8"?>
<articles type="array">
<article>
…
$ curl -H 'Accept: application/json' http://localhost:3000/articles
[{"article":{"updated_at":"2010-03-05T16:08:33Z",…}}]
The Accept Header
Note how the responses changed as I modified
the header but hit the URL
102. $ curl http://localhost:3000/articles
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
…
$ curl -H 'Accept: application/xml' http://localhost:3000/articles
<?xml version="1.0" encoding="UTF-8"?>
<articles type="array">
<article>
…
$ curl -H 'Accept: application/json' http://localhost:3000/articles
[{"article":{"updated_at":"2010-03-05T16:08:33Z",…}}]
The Accept Header
Note how the responses changed as I modified
the header but hit the URL
104. Atom Feeds
A very popular use of response formats is to create
Atom feeds
105. Atom Feeds
A very popular use of response formats is to create
Atom feeds
Rails adds a little syntactic sugar for this with some
helper methods and the use of the Builder library
106. Atom Feeds
A very popular use of response formats is to create
Atom feeds
Rails adds a little syntactic sugar for this with some
helper methods and the use of the Builder library
Builder allows you to generate XML with a Ruby DSL
108. def index
@articles = Article.all(:order => "created_at DESC")
respond_to do |format|
format.html # take the default action
format.atom # take the default action
format.xml do
render :xml => @articles.to_xml
end
format.json do
render :json => @articles.to_json
end
end
end
Rendering Atom
I’ve added the format and set an ordering that
will help us set good Atom dates
109. def index
@articles = Article.all(:order => "created_at DESC")
respond_to do |format|
format.html # take the default action
format.atom # take the default action
format.xml do
render :xml => @articles.to_xml
end
format.json do
render :json => @articles.to_json
end
end
end
Rendering Atom
I’ve added the format and set an ordering that
will help us set good Atom dates
110. def index
@articles = Article.all(:order => "created_at DESC")
respond_to do |format|
format.html # take the default action
format.atom # take the default action
format.xml do
render :xml => @articles.to_xml
end
format.json do
render :json => @articles.to_json
end
end
end
Rendering Atom
I’ve added the format and set an ordering that
will help us set good Atom dates
112. atom_feed do |feed|
feed.title("My Blog Articles")
feed.updated(@articles.first.created_at)
@articles.each do |article|
feed.entry(article) do |entry|
entry.title(article.title)
entry.content(article.body, :type => 'html')
entry.author do |author|
author.name("JEG2") # article.user.name
end
end
end
end
XML With Builder
Builder generates XML (or Atom) from
the nested structure of Ruby blocks
113. atom_feed do |feed|
feed.title("My Blog Articles")
feed.updated(@articles.first.created_at)
@articles.each do |article|
feed.entry(article) do |entry|
entry.title(article.title)
entry.content(article.body, :type => 'html')
entry.author do |author|
author.name("JEG2") # article.user.name
end
end
end
end
XML With Builder
Builder generates XML (or Atom) from
the nested structure of Ruby blocks
114. atom_feed do |feed|
feed.title("My Blog Articles")
feed.updated(@articles.first.created_at)
@articles.each do |article|
feed.entry(article) do |entry|
entry.title(article.title)
entry.content(article.body, :type => 'html')
entry.author do |author|
author.name("JEG2") # article.user.name
end
end
end
end
XML With Builder
Builder generates XML (or Atom) from
the nested structure of Ruby blocks
115. atom_feed do |feed|
feed.title("My Blog Articles")
feed.updated(@articles.first.created_at)
@articles.each do |article|
feed.entry(article) do |entry|
entry.title(article.title)
entry.content(article.body, :type => 'html')
entry.author do |author|
author.name("JEG2") # article.user.name
end
end
end
end
XML With Builder
Builder generates XML (or Atom) from
the nested structure of Ruby blocks
116. atom_feed do |feed|
feed.title("My Blog Articles")
feed.updated(@articles.first.created_at)
@articles.each do |article|
feed.entry(article) do |entry|
entry.title(article.title)
entry.content(article.body, :type => 'html')
entry.author do |author|
author.name("JEG2") # article.user.name
end
end
end
end
XML With Builder
Builder generates XML (or Atom) from
the nested structure of Ruby blocks
117. An Atom Feed
Rails does a lot of work for us:
adding ID’s and links, converting dates, …
118. $ curl -H 'Accept: application/atom+xml' http://localhost:3000/articles
<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
<id>tag:localhost,2005:/articles</id>
<link type="text/html" rel="alternate" href="http://localhost:3000"/>
<link type="application/atom+xml" rel="self" href="http://localhost:3000/articles"/>
<title>My Blog Articles</title>
<updated>2010-03-05T16:08:33Z</updated>
<entry>
<id>tag:localhost,2005:Article/1</id>
<published>2010-03-05T16:08:33Z</published>
<updated>2010-03-05T16:08:33Z</updated>
<link type="text/html" rel="alternate" href="http://localhost:3000/articles/1"/>
<title>The CRUD</title>
<content type="html">Lorem ipsum…</content>
<author>
<name>JEG2</name>
</author>
</entry>
</feed>
An Atom Feed
Rails does a lot of work for us:
adding ID’s and links, converting dates, …
119. $ curl -H 'Accept: application/atom+xml' http://localhost:3000/articles
<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
<id>tag:localhost,2005:/articles</id>
<link type="text/html" rel="alternate" href="http://localhost:3000"/>
<link type="application/atom+xml" rel="self" href="http://localhost:3000/articles"/>
<title>My Blog Articles</title>
<updated>2010-03-05T16:08:33Z</updated>
<entry>
<id>tag:localhost,2005:Article/1</id>
<published>2010-03-05T16:08:33Z</published>
<updated>2010-03-05T16:08:33Z</updated>
<link type="text/html" rel="alternate" href="http://localhost:3000/articles/1"/>
<title>The CRUD</title>
<content type="html">Lorem ipsum…</content>
<author>
<name>JEG2</name>
</author>
</entry>
</feed>
An Atom Feed
Rails does a lot of work for us:
adding ID’s and links, converting dates, …
120. $ curl -H 'Accept: application/atom+xml' http://localhost:3000/articles
<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
<id>tag:localhost,2005:/articles</id>
<link type="text/html" rel="alternate" href="http://localhost:3000"/>
<link type="application/atom+xml" rel="self" href="http://localhost:3000/articles"/>
<title>My Blog Articles</title>
<updated>2010-03-05T16:08:33Z</updated>
<entry>
<id>tag:localhost,2005:Article/1</id>
<published>2010-03-05T16:08:33Z</published>
<updated>2010-03-05T16:08:33Z</updated>
<link type="text/html" rel="alternate" href="http://localhost:3000/articles/1"/>
<title>The CRUD</title>
<content type="html">Lorem ipsum…</content>
<author>
<name>JEG2</name>
</author>
</entry>
</feed>
An Atom Feed
Rails does a lot of work for us:
adding ID’s and links, converting dates, …
121. $ curl -H 'Accept: application/atom+xml' http://localhost:3000/articles
<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
<id>tag:localhost,2005:/articles</id>
<link type="text/html" rel="alternate" href="http://localhost:3000"/>
<link type="application/atom+xml" rel="self" href="http://localhost:3000/articles"/>
<title>My Blog Articles</title>
<updated>2010-03-05T16:08:33Z</updated>
<entry>
<id>tag:localhost,2005:Article/1</id>
<published>2010-03-05T16:08:33Z</published>
<updated>2010-03-05T16:08:33Z</updated>
<link type="text/html" rel="alternate" href="http://localhost:3000/articles/1"/>
<title>The CRUD</title>
<content type="html">Lorem ipsum…</content>
<author>
<name>JEG2</name>
</author>
</entry>
</feed>
An Atom Feed
Rails does a lot of work for us:
adding ID’s and links, converting dates, …
122. Support Head Content
I have inserted a placeholder that will allow pages
to insert content into the document head
123. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>
<%= ["My Blog", yield(:page_title)].compact.join(" : ") %>
</title>
<%= yield :head %>
</head>
<body>
<%= yield %>
</body>
</html>
Support Head Content
I have inserted a placeholder that will allow pages
to insert content into the document head
124. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>
<%= ["My Blog", yield(:page_title)].compact.join(" : ") %>
</title>
<%= yield :head %>
</head>
<body>
<%= yield %>
</body>
</html>
Support Head Content
I have inserted a placeholder that will allow pages
to insert content into the document head
125. An Auto Discovery Link
Now we can have the HTML page inform our
browser of the existence of the feed
126. <% content_for :head do %>
<%= auto_discovery_link_tag :atom, :format => :atom %>
<% end %>
<h1>Articles</h1>
<ul>
<%= render @articles %>
</ul>
An Auto Discovery Link
Now we can have the HTML page inform our
browser of the existence of the feed
127. <% content_for :head do %>
<%= auto_discovery_link_tag :atom, :format => :atom %>
<% end %>
<h1>Articles</h1>
<ul>
<%= render @articles %>
</ul>
An Auto Discovery Link
Now we can have the HTML page inform our
browser of the existence of the feed
133. Other Types of Renders
Rails can respond to any Mime Type format
134. Other Types of Renders
Rails can respond to any Mime Type format
You can also choose to send a file back to the browser
135. Other Types of Renders
Rails can respond to any Mime Type format
You can also choose to send a file back to the browser
Or generate data programmatically that is passed as
a file
136. Other Types of Renders
Rails can respond to any Mime Type format
You can also choose to send a file back to the browser
Or generate data programmatically that is passed as
a file
I use this to stream CSV back to browsers