# Routing issue

**URL:** <https://www.ruby-forum.com/t/routing-issue/208297>\
**Category:** Rails\
**Created:** [June 14, 2011, 2:19pm UTC](https://www.ruby-forum.com/t/routing-issue/208297 "2011-06-14T14:19:02Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [June 14, 2011, 2:19pm UTC](https://www.ruby-forum.com/t/routing-issue/208297/1 "2011-06-14T14:19:02Z")

</div>

Hello

I have this in my route.rb

namespace :admin do  
resources :accounts do  
resources :portals do  
post ‘create’  
post ‘edit’  
post ‘show’  
end  
end  
end

Actually, from the beginning it looked like this:

namespace :admin do  
resources :accounts do  
resources :portals  
end  
end

Before, but even now, when I go to  
/admin/accounts/1/portals

Then the method named create was executed.  
Even when I go to /admin/accounts/1/portals/create  
the same method is executed

I need now to execute the method edit

If I try to call it with GET, then it works. So pasting in the  
browser  
/admin/accounts/1/portals/edit

works.

But the thing is that this should be a POST. So when I try to access  
this page, with curl, specifying it is a POST, then I get a

Routing Error

No route matches “/admin/accounts/1/portals/edit”

So it didnt help putting the specific route with post and get into the  
admin-portals-resource.

What is wrong? Maybe a simple thing, but Im very unexperienced in ROR.  
Thanks.

---

<div class="post-metadata">

**Author:** ![Sta\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Sta\_C](https://www.ruby-forum.com/u/Sta_C)\
**Post date:** [June 14, 2011, 3:14pm UTC](https://www.ruby-forum.com/t/routing-issue/208297/2 "2011-06-14T15:14:07Z")

</div>

On Jun 14, 2011, at 8:17 AM, Sta C. wrote:

> ```
> end
> 
> ```
> 
> browser
> 
> So it didnt help putting the specific route with post and get into the  
> admin-portals-resource.
> 
> What is wrong? Maybe a simple thing, but Im very unexperienced in ROR.  
> Thanks.

What do you see when you type rake routes (from inside your project  
root) in your terminal?

Walter

---

<div class="post-metadata">

**Author:** ![Sta\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Sta\_C](https://www.ruby-forum.com/u/Sta_C)\
**Post date:** [June 14, 2011, 3:44pm UTC](https://www.ruby-forum.com/t/routing-issue/208297/3 "2011-06-14T15:44:25Z")

</div>

2011/6/14 Walter D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> What do you see when you type rake routes (from inside your project root)  
> in your terminal?

Well, I get an error sigh:

rake aborted!  
You have already activated rake 0.9.1, but your Gemfile requires rake  
0.8.7.  
Consider using bundle exec.  
/usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:31:in  
`setup' /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.14/lib/bundler/spec_set.rb:12:in `each’  
/usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.14/lib/bundler/spec\_set.rb:12:in  
`each' /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:17:in `setup’  
/usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.14/lib/bundler.rb:107:in  
`setup' /Users/alfredocapasso/Sites/git/zoomvision/flash-wip/config/boot.rb:8 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem\_original\_require’  
/usr/local/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:36:in  
`require' /Users/alfredocapasso/Sites/git/zoomvision/flash-wip/config/application.rb:1 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem\_original\_require’  
/usr/local/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:36:in  
`require' /Users/alfredocapasso/Sites/git/zoomvision/flash-wip/Rakefile:4 /usr/local/lib/ruby/gems/1.8/gems/rake-0.9.1/lib/rake/rake_module.rb:25:in `load’  
/usr/local/lib/ruby/gems/1.8/gems/rake-0.9.1/lib/rake/rake\_module.rb:25:in  
`load_rakefile' /usr/local/lib/ruby/gems/1.8/gems/rake-0.9.1/lib/rake/application.rb:495:in `raw\_load\_rakefile’  
/usr/local/lib/ruby/gems/1.8/gems/rake-0.9.1/lib/rake/application.rb:78:in  
`load_rakefile' /usr/local/lib/ruby/gems/1.8/gems/rake-0.9.1/lib/rake/application.rb:129:in `standard\_exception\_handling’  
/usr/local/lib/ruby/gems/1.8/gems/rake-0.9.1/lib/rake/application.rb:77:in  
`load_rakefile' /usr/local/lib/ruby/gems/1.8/gems/rake-0.9.1/lib/rake/application.rb:61:in `run’  
/usr/local/lib/ruby/gems/1.8/gems/rake-0.9.1/lib/rake/application.rb:129:in  
`standard_exception_handling' /usr/local/lib/ruby/gems/1.8/gems/rake-0.9.1/lib/rake/application.rb:59:in `run’  
/usr/local/lib/ruby/gems/1.8/gems/rake-0.9.1/bin/rake:32  
/usr/local/bin/rake:19:in `load’  
/usr/local/bin/rake:19

---

<div class="post-metadata">

**Author:** ![Sta\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Sta\_C](https://www.ruby-forum.com/u/Sta_C)\
**Post date:** [June 14, 2011, 3:51pm UTC](https://www.ruby-forum.com/t/routing-issue/208297/4 "2011-06-14T15:51:51Z")

</div>

On Jun 14, 2011, at 9:42 AM, Sta C. wrote:

> 2011/6/14 Walter D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> What do you see when you type rake routes (from inside your project  
> root) in your terminal?
> 
> Well, I get an error sigh:
> 
> rake aborted!

Cue Mythbusters theme music: “Well, there’s your problem right there…”

Walter

---

<div class="post-metadata">

**Author:** ![Sta\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Sta\_C](https://www.ruby-forum.com/u/Sta_C)\
**Post date:** [June 14, 2011, 4:04pm UTC](https://www.ruby-forum.com/t/routing-issue/208297/5 "2011-06-14T16:04:14Z")

</div>

2011/6/14 Walter D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> Cue Mythbusters theme music: “Well, there’s your problem right there…”

Ok, running bundle exec rake routes solves the problem.  
Now I can see all the routes. There are a lot.  
Those related to my problem are:

portal\_edit  
POST  
/admin/accounts/:account\_id/portals/:portal\_id/edit(.:format)  
{:action=\>“edit”, :controller=\>“admin/portals”}

edit\_portal  
GET  
/portals/:id/edit(.:format)  
{:action=\>“edit”, :controller=\>“portals”}

edit\_admin\_account\_portal  
GET  
/admin/accounts/:account\_id/portals/:id/edit(.:format)  
{:action=\>“edit”, :controller=\>“admin/portals”}

edit\_admin\_account  
GET  
/admin/accounts/:id/edit(.:format)  
{:action=\>“edit”, :controller=\>“admin/accounts”}

Does this tell you somthing?

---

<div class="post-metadata">

**Author:** ![Sta\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Sta\_C](https://www.ruby-forum.com/u/Sta_C)\
**Post date:** [June 14, 2011, 4:28pm UTC](https://www.ruby-forum.com/t/routing-issue/208297/6 "2011-06-14T16:28:24Z")

</div>

On Jun 14, 2011, at 10:02 AM, Sta C. wrote:

> portal\_edit  
> POST  
> /admin/accounts/:account\_id/portals/:portal\_id/edit(.:format)  
> {:action=\>“edit”, :controller=\>“admin/portals”}

This looks like the path you want to post your form results to, but if  
this is a POST, you should be hitting :action =\> ‘update’ rather than  
‘edit’.

To load the form that you will fill with new data for your update, you  
would have a matching route that used GET, and hit :action =\> ‘edit’.

If you don’t want to use REST conventions (GET to load the edit, form  
POST to accept the update) then you need to get out of that end of the  
pool and use older-style non-RESTful routes, which you can spot by  
their dangling ids:

/admin/accounts/2/portals/edit/4

Have a look at the very bottom of your routes file for comments about  
configuring those, I’m not sure what the syntax would be in Rails 3,  
haven’t done those since Rails 2.

Walter

---

<div class="post-metadata">

**Author:** ![Sta\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Sta\_C](https://www.ruby-forum.com/u/Sta_C)\
**Post date:** [June 14, 2011, 5:04pm UTC](https://www.ruby-forum.com/t/routing-issue/208297/7 "2011-06-14T17:04:18Z")

</div>

On Jun 14, 2011, at 10:46 AM, Sta C. wrote:

> So you say the only solution is to add a custom route? Do you mean

There’s the nut of the problem right there. You don’t ever want to  
POST to the ‘edit’ route. You want to POST to the ‘update’ route. So  
if your curl application is already aware of the format of the element  
you’re updating, all you need to do is POST to ‘update’ and everything  
will Just Work. You only ever hit the (GET) ‘edit’ route when you  
want to receive back a populated form, ready for editing. That form is  
set to POST to the ‘update’ route.

The reason why ‘create’ works for you now is because when you want to  
create a new widget in Rails, you GET the ‘new’ route, which returns  
an empty form ready for completion, and that form POSTs to the  
‘create’ route.

Walter

---

<div class="post-metadata">

**Author:** ![Sta\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Sta\_C](https://www.ruby-forum.com/u/Sta_C)\
**Post date:** [June 14, 2011, 4:47pm UTC](https://www.ruby-forum.com/t/routing-issue/208297/8 "2011-06-14T16:47:33Z")

</div>

2011/6/14 Walter D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> /admin/accounts/2/portals/edit/4
> 
> Have a look at the very bottom of your routes file for comments about  
> configuring those, I’m not sure what the syntax would be in Rails 3, haven’t  
> done those since Rails 2.
> 
> Walter

Well, I dont care very much how. The thing is that create and edit will  
be  
called from another application through curl. So I will never need to go  
to  
the presentation page for edit and create. It is just enough that there  
will  
be route for when the form is posted.

As I said, it works for create. But not for edit. I wonder why it works  
for  
create but not edit.

So you say the only solution is to add a custom route? Do you mean that  
kind  
of routes like:

# This is a legacy wild controller route that’s not recommended for

RESTful  
applications.

# Note: This route will make all actions in every controller

accessible  
via GET requests.

# match ‘:controller(/:action(/:id(.:format)))’

If yes: But this talks about GET, hoe can I make t work for POST?

---

<div class="post-metadata">

**Author:** ![Sta\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Sta\_C](https://www.ruby-forum.com/u/Sta_C)\
**Post date:** [June 15, 2011, 10:31am UTC](https://www.ruby-forum.com/t/routing-issue/208297/9 "2011-06-15T10:31:41Z")

</div>

2011/6/14 Walter D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> create a new widget in Rails, you GET the ‘new’ route, which returns an  
> empty form ready for completion, and that form POSTs to the ‘create’ route.
> 
> Walter

Ok, but if I now have the route that looks like this:

namespace :admin do  
resources :accounts do  
resources :portals do  
post ‘create’  
post ‘update’  
post ‘show’  
end  
end  
end

And then in the controller I have both (to be sure, I dont know which  
one of  
edit and update I should define)  
I have:

def update

```
render :text => "update"
return

```

end

def edit

```
render :text => "edit"
return

```

end

Then going with curl to the url  
[http://localhost:3000/admin/accounts/1/portals/edit](http://localhost:3000/admin/accounts/1/portals/edit)  
or even  
[http://localhost:3000/admin/accounts/1/portals/update](http://localhost:3000/admin/accounts/1/portals/update)

still shows the error NO ROUTE MATCHES

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![Sta\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Sta\_C](https://www.ruby-forum.com/u/Sta_C)\
**Post date:** [June 14, 2011, 5:06pm UTC](https://www.ruby-forum.com/t/routing-issue/208297/10 "2011-06-14T17:06:09Z")

</div>

On 14 June 2011 15:46, Sta C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Walter
> 
> Well, I dont care very much how. The thing is that create and edit will be  
> called from another application through curl. So I will never need to go to  
> the presentation page for edit and create. It is just enough that there will  
> be route for when the form is posted.
> 
> As I said, it works for create. But not for edit. I wonder why it works for  
> create but not edit.

As Walter said it is because you should be using update not edit. In  
normal use with a browser new is used to get a form to fill in then  
create is used to create the record, edit is used to get the form for  
editing a record then update is used to do the update. So the form  
should be posted to update not edit and that is what the standard  
routes are set up for.

> So you say the only solution is to add a custom route? Do you mean that kind  
> of routes like:

No, just use the standard _update_ route

Colin

---

<div class="post-metadata">

**Author:** ![Sta\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Sta\_C](https://www.ruby-forum.com/u/Sta_C)\
**Post date:** [June 15, 2011, 10:42am UTC](https://www.ruby-forum.com/t/routing-issue/208297/11 "2011-06-15T10:42:51Z")

</div>

On 15 June 2011 09:30, Sta C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > The reason why ‘create’ works for you now is because when you want to  
> > post ‘create’  
> > def update
> 
> Then going with curl to the url  
> [http://localhost:3000/admin/accounts/1/portals/edit](http://localhost:3000/admin/accounts/1/portals/edit)  
> or even  
> [http://localhost:3000/admin/accounts/1/portals/update](http://localhost:3000/admin/accounts/1/portals/update)
> 
> still shows the error NO ROUTE MATCHES

What does rake routes show? Is the url you are using above contained  
there?

Colin

---

<div class="post-metadata">

**Author:** ![Sta\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Sta\_C](https://www.ruby-forum.com/u/Sta_C)\
**Post date:** [June 15, 2011, 10:58am UTC](https://www.ruby-forum.com/t/routing-issue/208297/12 "2011-06-15T10:58:19Z")

</div>

2011/6/15 Sta C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> > {:action=\>“update”, :controller=\>“admin/portals”}
> > 
> > PUT /admin/accounts/:id(.:format)  
> > {:action=\>“update”, :controller=\>“admin/accounts”}

And I see that accessing them as GET works. So typing the address in the  
browser shows in the logs that the page was accessed as GET, and I dont  
get  
any route error.

---

<div class="post-metadata">

**Author:** ![Sta\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Sta\_C](https://www.ruby-forum.com/u/Sta_C)\
**Post date:** [June 15, 2011, 10:54am UTC](https://www.ruby-forum.com/t/routing-issue/208297/13 "2011-06-15T10:54:37Z")

</div>

2011/6/15 Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> What does rake routes show? Is the url you are using above contained  
> there?
> 
> Colin

Well, among those that I think are relevent I can only see:

portal\_update POST  
/admin/accounts/:account\_id/portals/:portal\_id/update(.:format)  
{:action=\>“update”, :controller=\>“admin/portals”}

PUT /admin/accounts/:account\_id/portals/:id(.:format)  
{:action=\>“update”, :controller=\>“admin/portals”}

PUT /admin/accounts/:id(.:format)  
{:action=\>“update”, :controller=\>“admin/accounts”}

---

<div class="post-metadata">

**Author:** ![Sta\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Sta\_C](https://www.ruby-forum.com/u/Sta_C)\
**Post date:** [June 15, 2011, 11:03am UTC](https://www.ruby-forum.com/t/routing-issue/208297/14 "2011-06-15T11:03:16Z")

</div>

On 15 June 2011 09:53, Sta C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> portal\_update POST  
> /admin/accounts/:account\_id/portals/:portal\_id/update(.:format)  
> {:action=\>“update”, :controller=\>“admin/portals”}
> 
> PUT /admin/accounts/:account\_id/portals/:id(.:format)  
> {:action=\>“update”, :controller=\>“admin/portals”}
> 
> PUT /admin/accounts/:id(.:format)  
> {:action=\>“update”, :controller=\>“admin/accounts”}

Right, so you can see that the routes you want are not there. As you  
can see, the update route requires an id for the portal, so it knows  
which portal to update, and you have not provided that in your url.

Colin

---

<div class="post-metadata">

**Author:** ![Sta\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Sta\_C](https://www.ruby-forum.com/u/Sta_C)\
**Post date:** [June 15, 2011, 11:24am UTC](https://www.ruby-forum.com/t/routing-issue/208297/15 "2011-06-15T11:24:18Z")

</div>

2011/6/15 Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> Right, so you can see that the routes you want are not there. As you  
> can see, the update route requires an id for the portal, so it knows  
> which portal to update, and you have not provided that in your url.
> 
> Colin
> 
> Are you sure?  
> I see that I send the ID both for get and post.  
> With GET i put this in the browser:  
> [http://localhost:3000/admin/accounts/133/portals/update](http://localhost:3000/admin/accounts/133/portals/update)

And the log shows that I requested a GET, and there are no routes error.

But from CURL I get route error:

Started POST “/admin/accounts/133/portals/update” for 127.0.0.1 at Wed  
Jun  
15 11:06:50 +0200 2011

ActionController::RoutingError (No route matches  
“/admin/accounts/133/portals/update”):

But you can see that the ID was there:  
/admin/accounts/133/portals/update

---

<div class="post-metadata">

**Author:** ![Sta\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@Sta\_C](https://www.ruby-forum.com/u/Sta_C)\
**Post date:** [June 15, 2011, 11:29am UTC](https://www.ruby-forum.com/t/routing-issue/208297/16 "2011-06-15T11:29:51Z")

</div>

2011/6/15 Sta C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> Started POST “/admin/accounts/133/portals/update” for 127.0.0.1 at Wed Jun  
> 15 11:06:50 +0200 2011
> 
> ActionController::RoutingError (No route matches  
> “/admin/accounts/133/portals/update”):
> 
> But you can see that the ID was there:  
> /admin/accounts/133/portals/update

Oh I am sorry. I missunderstood. Yes, the problem was the portl\_id that  
was  
not attached. I mixed up account\_id and portal\_id. Thank you, it works  
now.
