这在我的道路上。 rb file:
resources :orders do
member do
get confirm
get cancel
end
end
Of course I wrote the confirm and cancel actions in my orders_controller.rb:
def confirm
@order = Order.find(params[:id])
#...
end
def cancel
@order = Order.find(params[:id])
#...
end
并且在我的“申请/调查/命令/”文件夹中创建了“confirm.html.erb”和“cancel.html.erb”。
但当我试图访问confirm_order_url或cancel_order_url时。 我总是犯这一rou错:
No route matches {:action=>"confirm", :controller=>"orders"}
Can t figure out what s missing! Any idea please?
PS: I m, using RoR v.3.1.0
EDIT#1: It seems the routes are set properly:
$ rake routes
[..]
confirm_order GET /orders/:id/confirm(.:format) {:action=>"confirm", :controller=>"orders"}
cancel_order GET /orders/:id/cancel(.:format) {:action=>"cancel", :controller=>"orders"}
orders GET /orders(.:format) {:action=>"index", :controller=>"orders"}
POST /orders(.:format) {:action=>"create", :controller=>"orders"}
new_order GET /orders/new(.:format) {:action=>"new", :controller=>"orders"}
edit_order GET /orders/:id/edit(.:format) {:action=>"edit", :controller=>"orders"}
order GET /orders/:id(.:format) {:action=>"show", :controller=>"orders"}
PUT /orders/:id(.:format) {:action=>"update", :controller=>"orders"}
DELETE /orders/:id(.:format) {:action=>"destroy", :controller=>"orders"}
[...]
EDIT#2: Maybe when I call confirm_order_url Rails doesn t know how to generate the route which should be like "orders/:id/confirm" because @order.id hasn t been assigned yet. But I am calling this method after @order.save. Namely, here:
if @order.save
response = PAYPAL_EXPRESS_GATEWAY.setup_purchase(@order.price_in_cents,
:ip => @order.ip_address,
:return_url => confirm_order_url,
:cancel_return_url => cancel_order_url
)
redirect_to PAYPAL_EXPRESS_GATEWAY.redirect_url_for(response.token)
So this leads to a subquestion: is @order.id set after the call to @order.save? And if not, how can I set it properly before calling an helper method such ad confirmation_order_url?
SOLUTION Thanks to Jayendra Patil i fixed my code this way:
if @order.save
response = PAYPAL_EXPRESS_GATEWAY.setup_purchase(@order.price_in_cents,
:ip => @order.ip_address,
:return_url => confirm_order_url(@order),
:cancel_return_url => cancel_order_url(@order)
)
redirect_to PAYPAL_EXPRESS_GATEWAY.redirect_url_for(response.token)
我错误地认为,铁路可以猜测,而I号令称之为“成员”,因此,答案是把“顺序”作为成员路线的理由。 谢谢。