我是 ruby on rails 的新手,只需运行示例https://guides.rubyonrails.org/getting_started.html#installing-rails
我想修改代码以处理 GET 请求,如下所示:
对于 GET 文章?special=false,返回所有文章
对于 GET Articles?special=true,返回标题中包含“token”的所有文章
bin/rails 路由文章 GET /articles(.:format) 文章#index
===app/controllers/articles_controller.rb
class ArticlesController < ApplicationController
def index
@articles = Article.all
end
=== app/views/articles/index.html.erb
<% @articles.each do |article| %>
<%= article.title %>
<%= article.text %>
<%= link_to 'Show', article_path(article) %>
<% end %>
============routes.rb=====
Rails.application.routes.draw do
get 'welcome/index'
resources :articles
root 'welcome#index'
end