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'
ルート.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 view
@car = Car.find(params[:id])
respond_to do |format|
format.html
format.json { render json: @car }
end
end
# GET /uploads/1/edit
def edit
@car = Car.find(params[:id])
end
def create
p_attr=params[:car]
p_attr[:car] = params[:car][:car].first if params[:car][:car].class == Array
@car = Car.new(p_attr)
respond_to do |format|
if @car.save
format.html {
render :json => [@car.to_jq_car].to_json,
:layout => false
}
format.json { render json: [@car.to_jq_car].to_json, status: :created, location: @car }
else
format.html { render action: "new" }
format.json{ render json: {name:(@arraydb.car_name).split(".").first ,error: @car.errors.messages[:car_name]}, :status =>422}
end
end
end
def destroy
@car = Car.find(params[:id])
@car.destroy
respond_to do |format|
format.html { redirect_to cars_url }
format.json { head :no_content }
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/}
前もって感謝します