Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何添加一个路由,该路由映射到RubyonRails3.1中StringExGem生成的slug url?_Ruby On Rails_Ruby On Rails 3_Routes - Fatal编程技术网

Ruby on rails 如何添加一个路由,该路由映射到RubyonRails3.1中StringExGem生成的slug url?

Ruby on rails 如何添加一个路由,该路由映射到RubyonRails3.1中StringExGem生成的slug url?,ruby-on-rails,ruby-on-rails-3,routes,Ruby On Rails,Ruby On Rails 3,Routes,这似乎很简单,在我的模型中,我有: class CustomerAccount < ActiveRecord::Base acts_as_url :name def to_param url # or whatever you set :url_attribute to end end 当我试图通过rake db:seed生成数据时,这会产生以下错误,或者至少我假设routes中的条目就是这样做的 undefined method `url' for :cust

这似乎很简单,在我的模型中,我有:

class CustomerAccount < ActiveRecord::Base

  acts_as_url :name

  def to_param
    url # or whatever you set :url_attribute to
  end

end
当我试图通过rake db:seed生成数据时,这会产生以下错误,或者至少我假设routes中的条目就是这样做的

undefined method `url' for :customer_accounts:Symbol
那么我需要做些什么来设置路线呢?我想要的是映射到customer account页面的视图

更新:

下面是在routes.rb中运行的代码,这是我在查看下面答案中的示例后发现的:

  resources :customer_accounts, :path => '/:id' do
    root :action => "show"
    member do
      get 'disabled'
      post 'update_billing'
    end
  end

如果要设置它,使您拥有如所示的路线,请执行以下操作:

get '/:id', :to => "customer_accounts#show"
如果您希望禁用此下方的
更新\u计费
操作:

get '/:id/disabled', :to => "customer_accounts#disabled"
post '/:id/update_billing', :to => "customer_accounts#update_billing"
或者(更整洁):


在更新中,我看到了你的例子,然后把它删掉了。
get '/:id', :to => "customer_accounts#show"
get '/:id/disabled', :to => "customer_accounts#disabled"
post '/:id/update_billing', :to => "customer_accounts#update_billing"
scope '/:id' do
  controller "customer_accounts" do
    root :action => "show"
    get 'disabled'
    get 'update_billing'
  end
end