1

これが私のRails2ルートです。

map.with_options :controller => 'foo', :conditions => { :method => :post } do |foo|
  foo.one 'one', :action => 'one'
  foo.two 'two', :action => 'two'

  foo.with_options :special_flag => 'true', :path_prefix => 'special_prefix',
    :conditions => { :method => :get } do |bar|
    bar.three '',        :action => 'for_blank'
    bar.four  'another', :action => 'for_another'
  end
end

この種のものをRails3に変換するにはどうすればよいですか?同じようにwith_optionsを使い続けますか?する代わりに、場合によってはより言葉になります

match '' => 'foo#for_blank'

私がやっている

match '', :action => 'for_blank'
4

3 に答える 3

2

ええ、with_optionsまだRails3で動作します。これを試してみてください。

map.with_options :controller => 'foo', :via => :post do
  match 'one', :action => 'one' #automatically generates one_* helpers
  match 'two', :action => 'two' #automatically generates two_* helpers

  foo.with_options :special_flag => 'true', :path => 'special_prefix', :via => :get do
    match '',        :action => 'for_blank'
    match  'another', :action => 'for_another', :as => "four" # as will change the helper methods names
  end
end

この:viaオプションは、醜いconditionsハッシュをより優れた構文に置き換えます。

于 2010-12-14T01:49:38.830 に答える
2

このような:

#JSON API
defaults :format => 'json' do
    get "log_out" => "sessions#destroy", :as => "log_out" 
    get "log_in"  => "sessions#new",     :as => "log_in" 
    get "sign_up" => "users#new",        :as => "sign_up" 

    resources :users, :sessions
end
于 2012-02-02T05:22:02.943 に答える
1

ルートが提供する方法に固執するようにしてください。Rails 3では非常に強力であり、必要なものすべてを提供する必要があります。詳細については、http: //guides.rubyonrails.org/routing.htmlを参照してください。

于 2010-12-14T01:25:22.783 に答える