微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Rails 3-需要Atom Feed帮助吗?

如何解决Rails 3-需要Atom Feed帮助吗?

| 无法在我的博客上使用Atom提要功能。我正在使用Kaminari插件文章进行分页-每页6个。使用下面的代码,当用户单击RSS Feed图像时,将要求他们登录而不是订阅Feed!任何帮助将不胜感激这个问题... application.html.erb 页面标题<%= auto_discovery_link_tag(:atom,feed_pa​​th,{:title => \“ My ATOM Feed \”})%> 页面正文<%= image_tag(\“ feed.png \”,{:alt => \'Atom Feed \',:class => \“ Feed \”})%>订阅 routes.rb
match \'/Feed\' => \'articles#Feed\',:as => :Feed,:defaults => { :format => \'atom\' }
article_controller
class ArticlesController < ApplicationController

before_filter :authenticate_user!,:except => [:index,:show]

# GET /articles
# GET /articles.xml
# display articles on the home page

def index
@articles = Article.published.page(params[:page]).per(6).ordered

respond_to do |format|
  format.html # index.html.erb
  format.xml  { render :xml => @articles }
  format.atom { render :atom => @articles }
end
end


# GET /articles/1
# GET /articles/1.xml
def show
@article = Article.find(params[:id])
@comment = Comment.new(:article=>@article)

respond_to do |format|
  format.html # show.html.erb
  format.xml  { render :xml => @article }
end
end



# GET /articles/new
# GET /articles/new.xml
def new
@article = Article.new

respond_to do |format|
  format.html # new.html.erb
  format.xml  { render :xml => @article }
end
end


# GET /articles/1/edit
def edit
@article = Article.find(params[:id])
authorize! :edit,@article
end

# POST /articles
# POST /articles.xml
def create
  #authorize! :create,@article
  @article = Article.new(params[:article])
  @article.user_id = current_user.id

respond_to do |format|
  if @article.save
    format.html { redirect_to(@article,:notice => \'Worry was successfully created.\') }
    format.xml  { render :xml => @article,:status => :created,:location => @article }
  else
    format.html { render :action => \"new\" }
    format.xml  { render :xml => @article.errors,:status => :unprocessable_entity }
  end
end
end

# PUT /articles/1
# PUT /articles/1.xml
def update
  @article = Article.find(params[:id])
authorize! :update,@article
respond_to do |format|
  if @article.update_attributes(params[:article])
    format.html { redirect_to(@article,:notice => \'Worry was successfully updated.\') }
    format.xml  { head :ok }
  else
    format.html { render :action => \"edit\" }
    format.xml  { render :xml => @article.errors,:status => :unprocessable_entity }
  end
end
end


# DELETE /articles/1
# DELETE /articles/1.xml
def destroy
@article = Article.find(params[:id])
authorize! :destroy,@article
@article.destroy

respond_to do |format|
  format.html { redirect_to(articles_url) }
  format.xml  { head :ok }
end
end

end
视图/文章/Feed.atom.builder
atom_Feed :language => \'en-US\' do |Feed|
Feed.title \"mysite.com\"
Feed.updated(@articles.blank? ? Time.Now : @articles.first.created_at)

@articles.each do |article|
Feed.entry article,:published => article.accepted do |entry|
  entry.title article.title

  entry.author do |author|
    author.name article.user.fullname
  end
end
end
end
    

解决方法

        在您的
articles_controller
中更新此行:
before_filter :authenticate_user!,:except => [:index,:show]
...与:
before_filter :authenticate_user!,:show,:feed]
这将阻止进行身份验证的请求。     ,        两个建议: 1)将
:url
:root_url
加到
atom_feed
呼叫中。 2)变更:
feed.updated @articles.first.created_at
至:
feed.updated(@articles.blank? ? Time.now : @articles.first.created_at)
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。