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.
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.
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?
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:
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.
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.
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.
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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.