I have a problem with my routing. When a user performs an illegal
checkout action (end time < start time) it should route back to to the
''checkout'' action. However, it is instead going to the
''edit'' action.
<b>''rake routes'' </b>
users GET /users(.:format)
{:controller=>"users",
:action=>"index"}
POST /users(.:format)
{:controller=>"users", :action=>"create"}
new_user GET /users/new(.:format)
{:controller=>"users", :action=>"new"}
edit_user GET /users/:id/edit(.:format)
{:controller=>"users", :action=>"edit"}
user GET /users/:id(.:format)
{:controller=>"users", :action=>"show"}
PUT /users/:id(.:format)
{:controller=>"users", :action=>"update"}
DELETE /users/:id(.:format)
{:controller=>"users", :action=>"destroy"}
new_session GET /session/new(.:format)
{:controller=>"sessions", :action=>"new"}
edit_session GET /session/edit(.:format)
{:controller=>"sessions", :action=>"edit"}
session GET /session(.:format)
{:controller=>"sessions", :action=>"show"}
PUT /session(.:format)
{:controller=>"sessions", :action=>"update"}
DELETE /session(.:format)
{:controller=>"sessions", :action=>"destroy"}
POST /session(.:format)
{:controller=>"sessions", :action=>"create"}
labs GET /labs(.:format)
{:controller=>"labs", :action=>"index"}
POST /labs(.:format)
{:controller=>"labs", :action=>"create"}
new_lab GET /labs/new(.:format)
{:controller=>"labs", :action=>"new"}
edit_lab GET /labs/:id/edit(.:format)
{:controller=>"labs", :action=>"edit"}
lab GET /labs/:id(.:format)
{:controller=>"labs", :action=>"show"}
PUT /labs/:id(.:format)
{:controller=>"labs", :action=>"update"}
DELETE /labs/:id(.:format)
{:controller=>"labs", :action=>"destroy"}
lab_categories GET /lab_categories(.:format)
{:controller=>"lab_categories", :action=>"index"}
POST /lab_categories(.:format)
{:controller=>"lab_categories", :action=>"create"}
new_lab_category GET /lab_categories/new(.:format)
{:controller=>"lab_categories", :action=>"new"}
edit_lab_category GET /lab_categories/:id/edit(.:format)
{:controller=>"lab_categories", :action=>"edit"}
lab_category GET /lab_categories/:id(.:format)
{:controller=>"lab_categories", :action=>"show"}
PUT /lab_categories/:id(.:format)
{:controller=>"lab_categories", :action=>"update"}
DELETE /lab_categories/:id(.:format)
{:controller=>"lab_categories", :action=>"destroy"}
checkout_index GET /checkout(.:format)
{:controller=>"checkout", :action=>"index"}
POST /checkout(.:format)
{:controller=>"checkout", :action=>"create"}
new_checkout GET /checkout/new(.:format)
{:controller=>"checkout", :action=>"new"}
edit_checkout GET /checkout/:id/edit(.:format)
{:controller=>"checkout", :action=>"edit"}
GET /checkout/:id(.:format)
{:controller=>"checkout", :action=>"show"}
PUT /checkout/:id(.:format)
{:controller=>"checkout", :action=>"update"}
DELETE /checkout/:id(.:format)
{:controller=>"checkout", :action=>"destroy"}
login /
{:controller=>"sessions", :action=>"new"}
signup /signup
{:controller=>"users", :action=>"new"}
myaccount /myaccount
{:controller=>"myaccount", :action=>"myaccount"}
logout /logout
{:controller=>"sessions", :action=>"destroy"}
/labs/checkout/:id
{:controller=>"checkout", :action=>"checkout"}
/labs/checkout/:id/update
{:controller=>"checkout", :action=>"update"}
checkout /labs/checkout/:id/edit
{:controller=>"checkout", :action=>"update"}
root /
{:controller=>"home", :action=>"index"}
/:controller/:action/:id
/:controller/:action/:id(.:format)
routes.rb:
map.checkout ''/labs/checkout/:id'', :controller =>
''checkout'', :action
=> ''checkout''
map.checkout ''/labs/checkout/:id/update'', :controller =>
''checkout'',
:action => ''update''
map.checkout ''/labs/checkout/:id/edit'', :controller =>
''checkout'',
:action => ''update''
map.root :controller => "home"
# default routes
map.connect '':controller/:action/:id''
map.connect '':controller/:action/:id.:format''
<b>CheckoutController update action: </b>
def update
@lab = Lab.find(params[:id])
respond_to do |format|
if @lab.update_attributes(params[:lab])
flash[:notice] = ''Lab was successfully
updated.''
format.html { redirect_to(@lab) }
format.xml { head :ok }
else
format.html { render :action =>
"checkout" }
format.xml { render :xml =>
@lab.errors, :status => :unprocessable_entity }
end
end
end
<b>LabController update </b>
def update
@lab = Lab.find(params[:id])
respond_to do |format|
if @lab.update_attributes(params[:lab])
flash[:notice] = ''Lab was successfully updated.''
format.html { redirect_to(@lab) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
#format.html { redirect_to :back }
format.xml { render :xml => @lab.errors, :status =>
:unprocessable_entity }
end
end
end
Let me know if there is something I forgot to include.
Thanks
--
Posted via http://www.ruby-forum.com/.
I think the issue is that you have a general route to the checkout controller and then you have a map.checkout route that is after the map.resources :checkout route. so when you use checkout_path you will get the edit task and not the checkout "route" that you have setup... Try changing map.checkout to map.checkout-something-else and see if that fixes the issue... On Jun 17, 2:42 pm, Tyler Knappe <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have a problem with my routing. When a user performs an illegal > checkout action (end time < start time) it should route back to to the > ''checkout'' action. However, it is instead going to the ''edit'' action. > > <b>''rake routes'' </b> > > users GET /users(.:format) {:controller=>"users", > :action=>"index"} > POST /users(.:format) > {:controller=>"users", :action=>"create"} > new_user GET /users/new(.:format) > {:controller=>"users", :action=>"new"} > edit_user GET /users/:id/edit(.:format) > {:controller=>"users", :action=>"edit"} > user GET /users/:id(.:format) > {:controller=>"users", :action=>"show"} > PUT /users/:id(.:format) > {:controller=>"users", :action=>"update"} > DELETE /users/:id(.:format) > {:controller=>"users", :action=>"destroy"} > new_session GET /session/new(.:format) > {:controller=>"sessions", :action=>"new"} > edit_session GET /session/edit(.:format) > {:controller=>"sessions", :action=>"edit"} > session GET /session(.:format) > {:controller=>"sessions", :action=>"show"} > PUT /session(.:format) > {:controller=>"sessions", :action=>"update"} > DELETE /session(.:format) > {:controller=>"sessions", :action=>"destroy"} > POST /session(.:format) > {:controller=>"sessions", :action=>"create"} > labs GET /labs(.:format) > {:controller=>"labs", :action=>"index"} > POST /labs(.:format) > {:controller=>"labs", :action=>"create"} > new_lab GET /labs/new(.:format) > {:controller=>"labs", :action=>"new"} > edit_lab GET /labs/:id/edit(.:format) > {:controller=>"labs", :action=>"edit"} > lab GET /labs/:id(.:format) > {:controller=>"labs", :action=>"show"} > PUT /labs/:id(.:format) > {:controller=>"labs", :action=>"update"} > DELETE /labs/:id(.:format) > {:controller=>"labs", :action=>"destroy"} > lab_categories GET /lab_categories(.:format) > {:controller=>"lab_categories", :action=>"index"} > POST /lab_categories(.:format) > {:controller=>"lab_categories", :action=>"create"} > new_lab_category GET /lab_categories/new(.:format) > {:controller=>"lab_categories", :action=>"new"} > edit_lab_category GET /lab_categories/:id/edit(.:format) > {:controller=>"lab_categories", :action=>"edit"} > lab_category GET /lab_categories/:id(.:format) > {:controller=>"lab_categories", :action=>"show"} > PUT /lab_categories/:id(.:format) > {:controller=>"lab_categories", :action=>"update"} > DELETE /lab_categories/:id(.:format) > {:controller=>"lab_categories", :action=>"destroy"} > checkout_index GET /checkout(.:format) > {:controller=>"checkout", :action=>"index"} > POST /checkout(.:format) > {:controller=>"checkout", :action=>"create"} > new_checkout GET /checkout/new(.:format) > {:controller=>"checkout", :action=>"new"} > edit_checkout GET /checkout/:id/edit(.:format) > {:controller=>"checkout", :action=>"edit"} > GET /checkout/:id(.:format) > {:controller=>"checkout", :action=>"show"} > PUT /checkout/:id(.:format) > {:controller=>"checkout", :action=>"update"} > DELETE /checkout/:id(.:format) > {:controller=>"checkout", :action=>"destroy"} > login / > {:controller=>"sessions", :action=>"new"} > signup /signup > {:controller=>"users", :action=>"new"} > myaccount /myaccount > {:controller=>"myaccount", :action=>"myaccount"} > logout /logout > {:controller=>"sessions", :action=>"destroy"} > /labs/checkout/:id > {:controller=>"checkout", :action=>"checkout"} > /labs/checkout/:id/update > {:controller=>"checkout", :action=>"update"} > checkout /labs/checkout/:id/edit > {:controller=>"checkout", :action=>"update"} > root / > {:controller=>"home", :action=>"index"} > /:controller/:action/:id > /:controller/:action/:id(.:format) > > routes.rb: > map.checkout ''/labs/checkout/:id'', :controller => ''checkout'', :action > => ''checkout'' > map.checkout ''/labs/checkout/:id/update'', :controller => ''checkout'', > :action => ''update'' > map.checkout ''/labs/checkout/:id/edit'', :controller => ''checkout'', > :action => ''update'' > map.root :controller => "home" > > # default routes > map.connect '':controller/:action/:id'' > map.connect '':controller/:action/:id.:format'' > > <b>CheckoutController update action: </b> > > def update > @lab = Lab.find(params[:id]) > > respond_to do |format| > if @lab.update_attributes(params[:lab]) > flash[:notice] = ''Lab was successfully > updated.'' > format.html { redirect_to(@lab) } > format.xml { head :ok } > else > format.html { render :action => > "checkout" } > format.xml { render :xml => > @lab.errors, :status => :unprocessable_entity } > end > end > end > > <b>LabController update </b> > > def update > @lab = Lab.find(params[:id]) > > respond_to do |format| > if @lab.update_attributes(params[:lab]) > flash[:notice] = ''Lab was successfully updated.'' > format.html { redirect_to(@lab) } > format.xml { head :ok } > else > format.html { render :action => "edit" } > #format.html { redirect_to :back } > format.xml { render :xml => @lab.errors, :status => > :unprocessable_entity } > end > end > end > > Let me know if there is something I forgot to include. > > Thanks > -- > Posted viahttp://www.ruby-forum.com/.
heimdull wrote:> I think the issue is that you have a general route to the checkout > controller and then you have a map.checkout route that is after the > map.resources :checkout route. so when you use checkout_path you will > get the edit task and not the checkout "route" that you have setup... > > Try changing map.checkout to map.checkout-something-else and see if > that fixes the issue... > > > > On Jun 17, 2:42�pm, Tyler Knappe <rails-mailing-l...-ARtvInVfO7m5VldFQK4jKA@public.gmane.orgt>I think the problem lies here: def update @lab = Lab.find(params[:id]) respond_to do |format| if @lab.update_attributes(params[:lab]) flash[:notice] = ''Lab was successfully updated.'' format.html { redirect_to(@lab) } format.xml { head :ok } else format.html { render :action => "edit" } If an unsuccessful update occurs the edit action is called, I changed this to another action and that action was called. However, what I can''t figure out is why this action is called from the Labs Controller, not from the Checkout Controller, where the checkout is called. I have an update action in the Checkout Controller.. -- Posted via http://www.ruby-forum.com/.
heimdull wrote:> I think the issue is that you have a general route to the checkout > controller and then you have a map.checkout route that is after the > map.resources :checkout route. so when you use checkout_path you will > get the edit task and not the checkout "route" that you have setup... > > Try changing map.checkout to map.checkout-something-else and see if > that fixes the issue... > > > > On Jun 17, 2:42�pm, Tyler Knappe <rails-mailing-l...-ARtvInVfO7m5VldFQK4jKA@public.gmane.orgt>You were on the right track. What I had not realized was that map.resources :controller generates the routes that I was seeing. I moved my map.checkout action to the top of the list and it now properly calls the checkout controller''s update function! -- Posted via http://www.ruby-forum.com/.
Tyler Knappe wrote:> heimdull wrote: >> I think the issue is that you have a general route to the checkout >> controller and then you have a map.checkout route that is after the >> map.resources :checkout route. so when you use checkout_path you will >> get the edit task and not the checkout "route" that you have setup... >> >> Try changing map.checkout to map.checkout-something-else and see if >> that fixes the issue... >> >> >> >> On Jun 17, 2:42�pm, Tyler Knappe <rails-mailing-l...@andreas-s.net> > > You were on the right track. What I had not realized was that > map.resources :controller generates the routes that I was seeing. I > moved my map.checkout action to the top of the list and it now properly > calls the checkout controller''s update function!I was mistaken, I had changed how the Labs update action behaved. I''m still having the same problem and I''ve changed all the routes around. -- Posted via http://www.ruby-forum.com/.