Rails的link_to用点而不是斜杠返回URL [英] Rails's link_to return url with dot instead of slash
本文介绍了Rails的link_to用点而不是斜杠返回URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用haml gem& amp;的Rails 3.0.9;带有rvm的Ruby 1.9.2-head
Rails 3.0.9 with haml gem & Ruby 1.9.2-head with rvm
我有订单资源.
routes.rb文件的片段
Fragment of routes.rb file
resources :orders
具有Order模型实例的调用link_to帮助程序将返回/order.2而不是/orders/2.
The call link_to helper with instance of the Order model return /order.2 instead of /orders/2.
order_controller.rb和index.html.haml的片段
Fragment of order_controller.rb and index.html.haml
#index.haml.html
%ul
- @orders.each do |item|
%li= link_to item.id, item #=> <a href="/order.2">2</a> instead of <a href="/orders/2">2</a>
#orders_controller.rb
def index
@orders = Order.all
end
我做错了什么?
我也有其他资源,但是它们工作正常.
I also have another resources but they work fine.
更新:
我的route.rb文件列表
Listing of my routes.rb file
YetApp::Application.routes.draw do
resources :categories, :products, :images, :orders, :small_images
match "/order", :to => "orders#new", :as=> 'order'
match "/success/:id", :to => "orders#success", :as=> 'order'
#namespace :signed do
# resources :products, :images, :categories
#end
root :to => 'pages#home'
match '/signed', :to => 'pages#signed', :as => 'signed'
match '/cooperation', :to => 'pages#cooperation', :as => 'cooperation'
match '/payment', :to => 'pages#payment', :as => 'payment'
match '/offer', :to => 'pages#offer', :as => 'offer'
match '/order', :to => 'pages#order', :as => 'order'
end
推荐答案
我认为您应该删除
match '/order', :to => ...
从您的路线文件中获取.
from your routes file.
这篇关于Rails的link_to用点而不是斜杠返回URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文