Beginning Rack dev here.
I have the basic blog app built found at http://guides.rubyonrails.org/getting_started.html
I can create a post, make changes….fine.
now…
I’m learning how to use Rack and I’m trying to create some middleware…
I’ve followed railscast #150 and #151…you can see my code here on github…
https://github.com/thefonso/form_challenge
when I do this at the url line in chrome…..http://localhost:3000/?name=foo
I get the desired result on my command line.
aleph@mage:~/Projects/form_challenge git:master$ rails s
=> Booting WEBrick
=> Rails 3.2.11 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2013-01-23 17:01:30] INFO WEBrick 1.3.1
[2013-01-23 17:01:30] INFO ruby 1.9.2 (2012-04-20) [x86_64-darwin12.2.0]
[2013-01-23 17:01:30] INFO WEBrick::HTTPServer#start: pid=32068 port=3000
{"name"=>"foo"}
Awesome, I can see data I send..So I expect that when I send data from my blog “create a post”
page…I should be able to capture that data.
BUT HOW do I get the rest of the app to work normally?
When I go to ……http://localhost:3000/
I get the Rack app…I want the Rails app
Now that I have this Rack middleware running….it “takes over” the rest of the app. I can not get to the ‘beginning’ of the Rails app or for that matter the form that I desire to receive data from.
Again the entire app is located here….
https://github.com/thefonso/form_challenge
Thanks for any help.
When writing middleware you have the responsibility to call through to the next middleware or the application. What your middleware does right now is simply respond with an empty response to every request, you never call through so that rails ever even sees the request.
You can fix it with this line:
@app.call(env)That is the critical line that continues the call chain through all the middleware.
So in your middleware, do
@app.call(env)instead ofreturn response.If you want to manipulate the response that comes from rails, do
And be sure to
When you are done.