【发布时间】:2020-03-31 07:08:44
【问题描述】:
如何改写以下网址
127.0.0.1:3000/article/index?type=1
作为
127.0.0.1:3000/article/category/brand
其中类型 1 是具有名牌的类别。
是否可以使用rails?
路由.rb
get "article/index"
article_controller.rb
def index
@article = Article.find(params[:type])
end
article.rb //模型
class Article < ApplicationRecord
belongs_to :category
end
链接到这条路线
<%= link_to category.name, {:controller => "article", :action => "index", :type => category.id }%>
【问题讨论】:
-
分享您的 routes.rb、文章和类别模型,以及查看代码。
-
请检查上面的更新代码
标签: ruby-on-rails ruby-on-rails-5 rails-routing