Ruby on rails ActionController::在Rails 4中创建rss提要时的未知信息
因此,我试图在我的rails 4应用程序中添加一个rss提要,但我正在努力解决一个ActionController::UnknownFormat,我知道它正在我的控制器中发生 hacks_controller.rbRuby on rails ActionController::在Rails 4中创建rss提要时的未知信息,ruby-on-rails,Ruby On Rails,因此,我试图在我的rails 4应用程序中添加一个rss提要,但我正在努力解决一个ActionController::UnknownFormat,我知道它正在我的控制器中发生 hacks_controller.rb def index @hacks = Hack.order('id desc').paginate(:page => params[:page], per_page: 5) end def f
def index
@hacks = Hack.order('id desc').paginate(:page => params[:page], per_page: 5)
end
def feed
@hacks = Hack.where(:active => true)
respond_to do |format|
format.atom { render :template => 'feed.atom.builder', :layout => false }
end
end
feed.atom.builder
atom_feed {language: 'en-US', url: root_url} do |feed|
feed.title "My own blog title"
feed.updated @hacks.maximum(:created_at)
@hacks.each do |hack|
feed.entry hack, {published: hack.created_at, updated: hack.updated_at} do |entry|
entry.title hack.title
entry.content post.text, type: 'html'
end
end
end
我试过换衣服
format.atom { render :template => 'feed.atom.builder', :layout => false }
到
但仍然不起作用。
痕迹是
ActionController::UnknownFormat - ActionController::UnknownFormat:
actionpack (4.1.1) lib/action_controller/metal/mime_responds.rb:440:in `retrieve_collector_from_mimes'
actionpack (4.1.1) lib/action_controller/metal/mime_responds.rb:256:in `respond_to'
() Users/javier/Desktop/definitive/app/controllers/hacks_controller.rb:14:in `feed'
actionpack (4.1.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.1.1) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.1.1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.1.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.1.1) lib/active_support/callbacks.rb:113:in `call'
我在rss格式上也有同样的问题,所以我不得不改变我的路线
defaults => { :format => 'rss' }
尝试按atom更改格式。在路由中。rb:
get 'feed' => 'hack#feed', format: 'atom'
就我而言,我必须补充一点
get 'feed' => 'hack#feed', format: 'rss'
到routes.rb中的行<代码>格式:“atom”尽管是atom提要,但它不起作用。您使用的是哪个版本的Rails?
get 'feed' => 'hack#feed', format: 'rss'