Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8720: polymorphic_path_accepts_options_hash.diff

File polymorphic_path_accepts_options_hash.diff, 1.4 kB (added by gbuesing, 2 years ago)
  • test/controller/polymorphic_routes_test.rb

    old new  
    2828  end 
    2929  alias_method :new_article_url, :articles_url 
    3030   
     31  def articles_path 
     32    '/articles' 
     33  end 
     34  alias_method :new_article_path, :articles_path 
     35   
    3136  def article_url(article) 
    3237    "http://www.example.com/articles/#{article.id}" 
    3338  end 
     
    6772    @comment.save 
    6873    assert_equal(article_comment_url(@article, @comment), polymorphic_url([@article, @comment])) 
    6974  end 
     75   
     76  def test_polymorphic_path 
     77    assert_equal(articles_path, polymorphic_path(@article)) 
     78    assert_equal(new_article_path, polymorphic_path(@article, :action => 'new')) 
     79  end 
    7080end 
  • lib/action_controller/polymorphic_routes.rb

    old new  
    2626      send(named_route, *args) 
    2727    end 
    2828 
    29     def polymorphic_path(record_or_hash_or_array
    30       polymorphic_url(record_or_hash_or_array, :routing_type => :path
     29    def polymorphic_path(record_or_hash_or_array, options = {}
     30      polymorphic_url(record_or_hash_or_array, options.merge(:routing_type => :path)
    3131    end 
    3232 
    3333    %w(edit new formatted).each do |action|