# Problem with CRUD

**URL:** <https://www.ruby-forum.com/t/problem-with-crud/104738>\
**Category:** Rails\
**Created:** [May 22, 2007, 12:01am UTC](https://www.ruby-forum.com/t/problem-with-crud/104738 "2007-05-22T00:01:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![madiba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58956e/32.png) [@madiba](https://www.ruby-forum.com/u/madiba)\
**Post date:** [May 22, 2007, 12:01am UTC](https://www.ruby-forum.com/t/problem-with-crud/104738/1 "2007-05-22T00:01:18Z")

</div>

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/](http://uzytkownik.jogger.pl/)  
(GNU/)Linux User: #425935 (see [http://counter.li.org/](http://counter.li.org/))

---

<div class="post-metadata">

**Author:** ![madiba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58956e/32.png) [@madiba](https://www.ruby-forum.com/u/madiba)\
**Post date:** [May 22, 2007, 1:39am UTC](https://www.ruby-forum.com/t/problem-with-crud/104738/2 "2007-05-22T01:39:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![madiba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58956e/32.png) [@madiba](https://www.ruby-forum.com/u/madiba)\
**Post date:** [May 22, 2007, 9:17am UTC](https://www.ruby-forum.com/t/problem-with-crud/104738/3 "2007-05-22T09:17:10Z")

</div>

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](http://localhost/books)]

Regards

---

<div class="post-metadata">

**Author:** ![madiba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58956e/32.png) [@madiba](https://www.ruby-forum.com/u/madiba)\
**Post date:** [May 22, 2007, 3:27pm UTC](https://www.ruby-forum.com/t/problem-with-crud/104738/4 "2007-05-22T15:27:03Z")

</div>

On 5/22/07, Russell N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![madiba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58956e/32.png) [@madiba](https://www.ruby-forum.com/u/madiba)\
**Post date:** [May 22, 2007, 2:21pm UTC](https://www.ruby-forum.com/t/problem-with-crud/104738/5 "2007-05-22T14:21:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![madiba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58956e/32.png) [@madiba](https://www.ruby-forum.com/u/madiba)\
**Post date:** [May 23, 2007, 8:39pm UTC](https://www.ruby-forum.com/t/problem-with-crud/104738/6 "2007-05-23T20:39:57Z")

</div>

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…
