

Rails6でRSSを出力すべく下記の手順でコードを  
書きましたが、エラーになってしまいます。  
どこの手順が誤っているのかわかりません。

**articles_controller.rb**

[code]

    def feed
      @articles = Article.all.order(created_at: :desc).page(params[:page]).per(6)
    end
    
[/code]

**routes.rb**

[code]

     get 'articles/feed'
    
[/code]

**views/articles/feed.html.rss**

[code]

    <rss version='2.0'>
        <channel>
            <title>1Kエクストリーム：更新情報</title>
            <link>https://www.onekextreme.com/</link>
            <description>1Kエクストリーム ブログ：新着</description>
    
            <% @articles.each do |article| %>
                <item>
                    <title><%= article.title %></title>
                    <link>https://www.onekextreme.com/articles/#{article.id}</link>
                    <description><%= article.content1 %></description>
                    <pubDate><%= article.created_at.strftime("%Y.%m.%d") %></pubDate>
                </item>
             <% end %>
        </channel>
    </rss>
    
[/code]

**ローカル環境でエラー**  
`http://localhost:3000/articles/feed`

[code]

    ArticlesController#feed is missing a template for request formats: text/html
    
    NOTE!
    Unless told otherwise, Rails expects an action to render a template with the same name,
    contained in a folder named after its controller. If this controller is an API responding with 204 (No Content),
    which does not require a template, then this error will occur when trying to access it via browser,
    since we expect an HTML template to be rendered for such requests. If that's the case, carry on.
    
[/code]


CC BY-SA 4.0
2022-12-11T03:18:41.487
92687
2022-12-11T06:17:16.630
2022-12-11T06:17:16.630
3060
37468
question
ruby-on-rails
Rails6でのRSS出力方法


テンプレートのファイル名を修正  
`views/articles/feed.html.rss` => `views/articles/feed.rss.erb`

`config/routes.rb` の修正

[code]

    get 'articles/feed', defaults: { format: :rss }
    
[/code]

でどうでしょうか


CC BY-SA 4.0
2022-12-11T06:13:00.840
92694
2022-12-11T06:13:00.840
55905
92687
answer