Rails's link_to return url with dot instead of slash

我的未来我决定 提交于 2019-12-12 10:11:17

问题


Rails 3.0.9 with haml gem & Ruby 1.9.2-head with rvm

I have order resource.

Fragment of routes.rb file

resources :orders

The call link_to helper with instance of the Order model return /order.2 instead of /orders/2.

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

What I do wrong?

I also have another resources but they work fine.

Update:

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

回答1:


I think you should remove the

match '/order', :to => ...

from your routes file.



来源:https://stackoverflow.com/questions/7568447/railss-link-to-return-url-with-dot-instead-of-slash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!