Rails Rails polymorphic_url

shooter · April 23, 2014 · Last by imlcl replied at April 24, 2014 · 2410 hits

polymorphic_url

polymorphic_url([:admin, @article, @comment]) => admin_article_comment_url(@article, @comment) 以后再也不用路径发愁了

配合这个使用效果更佳 😄

def find_commentable
  params.each do |name, value|
    if name =~ /(.+)_id$/
      return $1.classify.constantize.find(value)
    end
  end
  nil
end

http://railscasts.com/episodes/154-polymorphic-association

这的确是好东西👍

You need to Sign in before reply, if you don't have an account, please Sign up first.