Problem with CRUD

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

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?

First of all shouldn't that look more like:

class BooksController < ApplicationController   def create     # Code   end

  def index     # Code   end

  # 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| %>     <span class="title"><%= f.text_field :title %></span>     <span class="subtitle"><%= f.text_field :subtitle %></span>     <span class="action0">         <%= submit_tag "Save" %>     </span> <% 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

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

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 Olson <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...