madiba
May 22, 2007, 12:01am
1
What do I do wrong?
map.resources :books
def BooksController
def create
# Code
end
def index
# Code
end
Other code
end
If I make a POST to books_url it calls index. What’s wrong?
Regards
I’ve probably left my head… somewhere. Please wait untill I find it.
Homepage (pl_PL): http://uzytkownik.jogger.pl/
(GNU/)Linux User: #425935 (see http://counter.li.org/ )
First of all shouldn’t that look more like:
class BooksController < ApplicationController
def create
# Code
end
def index
# Code
end
Other code
end
Secondly, how are you issuing your POST?
From a form?
From the command line using a program like curl or wget?
If you are calling this from a form what does your view code look
like?
Are you really sure you are issuing a POST? How do you know this?
Are you using a TCP capture application to view the HTTP requests?
On Mon, 21 May 2007 16:38:39 -0700, Robert W. wrote:
Other code
end
Yes - sorry. I deleted too much.
Secondly, how are you issuing your POST? - From a form?
From the command line using a program like curl or wget?
No from browser.
If you are calling this from a form what does your view code look like?
<% remote_form_for :book, :url => books_url, :method => :post do |f| %>
<%= f.text_field :title %>
<%= f.text_field :subtitle %>
<%= submit_tag “Save” %>
<% end %>%
Are you really sure you are issuing a POST? How do you know this? Are
you using a TCP capture application to view the HTTP requests?
I believe logs:
Processing BooksController#index (for 127.0.0.1 at 2007-05-20 23:16:34)
[POST]
Session ID: 47fb4fa9620e309c841f699f080e1b99
Parameters: {“commit”=>“Save”, “action”=>“index”,
“controller”=>“books”, "book
"=>{“title”=>“Test1”, “subtitle”=>“Test2”}}
Book Load (0.002412) SELECT * FROM books
Rendering within layouts/application
Rendering books/index
Rendered books/_new (0.00332)
Completed in 0.56535 (1 reqs/sec) | Rendering: 0.00843 (1%) | DB:
0.00241
(0%) |
200 OK [http://localhost/books ]
Regards
On 5/22/07, Russell N. [email protected] wrote:
I’ve seen this behavior in my own app as well as someone else’s on
#rubyonrails IRC. I can’t duplicate it though. For my app, I had to end up
using
form_for :site, :url => “/sites/”, :html => {:method => :post} do |f|
because :action => :create [on the SitesController] sent the user back to
the index. Hard-coded urls work fine but Rails seems to choke on the proper
route generation. If I recall correctly, all these scenarios were with
RESTful routing but don’t hold me to that. Mine was, for sure, though.
That’s absurd, I don’t use any hardcoded URLs. Make sure your routes
file is correct. map.resources should go above the default map.connect
call.
–
Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
I’ve seen this behavior in my own app as well as someone else’s on
#rubyonrails IRC. I can’t duplicate it though. For my app, I had to end
up
using
form_for :site, :url => “/sites/”, :html => {:method => :post} do |f|
because :action => :create [on the SitesController] sent the user back
to
the index. Hard-coded urls work fine but Rails seems to choke on the
proper
route generation. If I recall correctly, all these scenarios were with
RESTful routing but don’t hold me to that. Mine was, for sure, though.
RSL
Rick O. <technoweenie@…> writes:
That’s absurd, I don’t use any hardcoded URLs. Make sure your routes
file is correct. map.resources should go above the default map.connect
call.
Thank you. I’ll try it.
Where can I find such things because I found it neighter in Rails doc
nor
in wiki…