0

我正在使用此示例在 Ruby on Rails 中上传文件。

我有一些路由问题:

错误:

ActionController::RoutingError (No route matches {:action=>"show", :controller=>"cars", :locale=>#<Car id: 19, car_name: "bwl",, created_at: "2013-01-27 19:12:13", updated_at: "2013-01-27 19:12:13">}):
  app/models/arraydb.rb:46:in `to_jq_car'

我发现问题出在 to_jq_car 函数和行中:

"delete_url" => car_path(self)

但我不知道如何纠正它。

路线.rb:

resources :cars
match '/show', :to =>'car#index'

root :to => 'cars#index'

汽车控制器.rb

class CarsController < ApplicationController


  def index
    @cars = Car.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @cars.map{|car| car.to_jq_car } }
    end
  end


  def show
    @car = Car.find(params[:id])

    respond_to do |format|
      format.html 
      format.json { render json: @car }
    end
  end

end

在 car.rb 我有以下功能:

 def to_jq_car
    {
      "name" => (read_attribute(:arraydb_name)).split(".").first,
      "url" => car.url(:original),
      "delete_url" => car_path(self),
      "delete_type" => "DELETE",


    }
  end

耙路线:

cars GET        (/:locale)/cars(.:format)                                  cars#index {:locale=>/en|de|es|ru|zh_cn|ar/}
POST       (/:locale)/cars(.:format)                                  cars#create {:locale=>/en|de|es|ru|zh_cn|ar/}
new_car GET        (/:locale)/cars/new(.:format)                              cars#new {:locale=>/en|de|es|ru|zh_cn|ar/}
edit_car GET        (/:locale)/cars/:id/edit(.:format)                         cars#edit {:locale=>/en|de|es|ru|zh_cn|ar/}
car GET        (/:locale)/cars/:id(.:format)                              cars#show {:locale=>/en|de|es|ru|zh_cn|ar/}
PUT        (/:locale)/cars/:id(.:format)                              cars#update {:locale=>/en|de|es|ru|zh_cn|ar/}
DELETE     (/:locale)/cars/:id(.:format)                              cars#destroy {:locale=>/en|de|es|ru|zh_cn|ar/}
show            (/:locale)/show(.:format)                                      car#index {:locale=>/en|de|es|ru|zh_cn|ar/}
root            /(:locale)(.:format)                                           cars#index {:locale=>/en|de|es|ru|zh_cn|ar/}

提前致谢

4

1 回答 1

1

错误原因:locale param

你有路线

cars#index {:locale=>/en|de|es|ru|zh_cn|ar/}

所以 :locale 值必须是列表中的其中一个en|de|es|ru|zh_cn|ar

并且您需要找到将此参数传递给控制器​​的位置并进行更正

您可以在 ApplicationController 中使用(或者您可能已经使用)

def default_url_options
  {:locale => I18n.locale}
end
于 2013-01-29T14:52:47.833 回答