我正在使用此example for uploading files in 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)
但我不知道如何纠正它。
routes.rb中:
resources :cars
match '/show', :to =>'car#index'
root :to => 'cars#index'
cars_controllers.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
rake routes:
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/}
提前致谢
答案 0 :(得分: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