Ruby on rails Rails 4-未经授权的用户可以';看不到依赖模型

Ruby on rails Rails 4-未经授权的用户可以';看不到依赖模型,ruby-on-rails,ruby,Ruby On Rails,Ruby,我按照Hartl指南和rubyonrails.org指南创建了一个网站。我注意到,未经授权的用户无法看到附加到我的文章模型的任何一个依赖模型。相关模型为Comment和Photocup 无论我如何尝试和显示它们,这些都不起作用: <%= render @article.photocups %> <%= render @article.comments %> \u gallery.html.erb部分呈现文章本身,但未经授权的用户看不到照片 对于授权用户来说,上述所有

我按照Hartl指南和rubyonrails.org指南创建了一个网站。我注意到,未经授权的用户无法看到附加到我的
文章
模型的任何一个依赖模型。相关模型为
Comment
Photocup

无论我如何尝试和显示它们,这些都不起作用:

 <%= render @article.photocups %>
 <%= render @article.comments %>
\u gallery.html.erb
部分呈现文章本身,但未经授权的用户看不到照片

对于授权用户来说,上述所有方法都非常有效

ArticlesController
允许索引和显示:

class ArticlesController < ApplicationController
skip_before_action :authorize, only: [:index, :show]
class-ArticlesController
我需要做什么才能让未经授权的用户看到这些依赖模型

谢谢你的帮助

编辑:在下面添加了文章控制器

  class ArticlesController < ApplicationController
  skip_before_action :authorize, only: [:index, :show]


   def check_box(method, options = {}, checked_value = "1",   unchecked_value = "0")
   end

   def remove_photo 
   @article = Article.find(params[:id])
   @article.photo = nil
   @article.save
   redirect_to @article
   end

   def feature
   @articles = Article.all
   end



  def index
    #displays the full list of articles
   @articles = Article.all
   #if User.find_by(id: session[:user_id])
   # render 'index', flash[:notice] => "Opps, need to be logged in to     do this!"
   #end

    #alt. method displays articles only created by the current user.
    #@articles = Article.where(user_id:current_user.id)
   end

   def showall
   @articles = current_user.articles
   end


  def show
    @article = Article.find(params[:id])
    @photocups = @article.photocups
   end

   def new
    @article = Article.new
   end

  def edit
    @article = Article.find(params[:id])
   end

   def create
    @article = current_user.articles.new(article_params)
   @article.author = current_user.name
    #@article = Article.new(article_params)

    if @article.save
    redirect_to @article
    else
  render 'new' #, :notice => "Opps, something not quite right!" 
    end 
   end

   def update
   @article = Article.find(params[:id])
   if @article.user_id == current_user.id || current_user.admin?
  #update author in case of user name change
    if @article.user_id == current_user.id
      @article.author = current_user.name
    end 
  if @article.update(article_params)
        redirect_to @article
    else
    render 'edit'
   end

    elsif
    redirect_to articles_path, :notice => "You do not have permission   to edit this resource."
    end

   end

  def destroy
   @article = Article.find(params[:id])

   if @article.user_id == current_user.id
    @article.destroy
    redirect_to articles_path, :notice => "Article Deleted."
   else
    redirect_to articles_path, :notice => "You do not have permission  to delete this resource."
   end
  end

   private
    def article_params
    params.require(:article).permit(:title, :text, :author, :manufacturer, :displacement, :model, :photo, :misc)
     end
    end
class-ArticlesController“Opps,需要登录才能执行此操作!”
#结束
#alt.方法仅显示由当前用户创建的项目。
#@articles=Article.where(用户\u id:current\u user.id)
结束
def showall
@articles=当前用户文章
结束
def秀
@article=article.find(参数[:id])
@photocups=@article.photocups
结束
def新
@article=article.new
结束
定义编辑
@article=article.find(参数[:id])
结束
def创建
@article=当前用户.articles.new(article\u参数)
@article.author=当前用户名
#@article=article.new(article_参数)
如果@article.save
将_重定向到@article
其他的
渲染“new”#,注意=>“哎呀,有点不对劲!”
结束
结束
def更新
@article=article.find(参数[:id])
如果@article.user_id==current_user.id | | current_user.admin?
#用户名更改时更新作者
如果@article.user\u id==current\u user.id
@article.author=当前用户名
结束
if@article.update(article_参数)
将_重定向到@article
其他的
渲染“编辑”
结束
埃尔西夫
重定向到文章路径:notice=>“您没有编辑此资源的权限。”
结束
结束
def销毁
@article=article.find(参数[:id])
如果@article.user\u id==current\u user.id
@第条销毁
重定向到文章路径,:notice=>“文章已删除。”
其他的
重定向到文章路径:notice=>“您没有删除此资源的权限。”
结束
结束
私有的
定义项目参数
参数要求(:文章)。许可(:标题,:文本,:作者,:制造商,:位移,:型号,:照片,:杂项)
结束
结束

您是否尝试在PhotoUpsController和CommentsController中添加相同的授权跳过,如下所示:

class PhotocupsController < ApplicationController
 skip_before_action :authorize, only: [:index, :show]
 #...
end


class CommentsController < ApplicationController
  skip_before_action :authorize, only: [:index, :show]
  #...
end
class-controller
我认为您阻止未经授权的用户查看评论和照片,可能是因为您在ApplicationController中添加了授权的常规检查

让我说!
再见

您是否尝试在PhotoUpsController和CommentsController中添加相同的授权跳过,如下所示:

class PhotocupsController < ApplicationController
 skip_before_action :authorize, only: [:index, :show]
 #...
end


class CommentsController < ApplicationController
  skip_before_action :authorize, only: [:index, :show]
  #...
end
class-controller
我认为您阻止未经授权的用户查看评论和照片,可能是因为您在ApplicationController中添加了授权的常规检查

让我说!
再见,我明白了。这与授权无关,只是数据库损坏。由于某些原因,未经授权(未登录)的用户被提供了不正确的文章ID。我通过清除日志,然后检查未登录用户和登录用户请求同一篇文章时发生的情况,找到了答案。我执行了db:reset,但无法重新创建问题

我知道了。这与授权无关,只是数据库损坏。由于某些原因,未经授权(未登录)的用户被提供了不正确的文章ID。我通过清除日志,然后检查未登录用户和登录用户请求同一篇文章时发生的情况,找到了答案。我执行了db:reset,但无法重新创建问题

首先,您需要向我们提供您控制器的完整源代码:)首先,您需要向我们提供您控制器的完整源代码:)恐怕这不起作用。我用过滤器做了很多实验。我的应用程序控制器确实有“before_action:authorize”,但我不相信这个问题。如果这是一个授权问题,它不会将我重定向到登录页面吗?没有,照片和评论根本没有显示出来。我担心这不起作用。我用过滤器做了很多实验。我的应用程序控制器确实有“before_action:authorize”,但我不相信这个问题。如果这是一个授权问题,它不会将我重定向到登录页面吗?事实并非如此,照片和评论根本就不会出现。