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'

路线.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 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/}

提前致谢

4

1 回答 1

0

刚遇到同样的问题并设法解决了

不确定您的情况是否与我的情况相同,但仍然..

只需检查您的网址是否没有尾随'/'

例如

http://localhost:3000/properties/

最后一个'/'在我的情况下没用

于 2013-02-27T14:37:07.497 回答