4

我有代码。 users_controller.rb

  def show
    @user = User.find_by id: params[:id]
    @microposts = @user.microposts.order_micropost.paginate(page: params[:page], per_page: 5)
  end

并查看/user/show.html.erb

<% provide :title, @user.name %>
<div class="row">
  <aside class="col-md-4">
    <section class="user-info">
      <h1>
        <%= gravatar_for @user %>
        <%= @user.name %>
      </h1>
    </section>
  </aside>
  <div class="col-md-8">
    <% if @user.microposts.any? %>
      <h3><%= t ".count_microposts", count:  @user.microposts.count %></h3>
      <ol class="microposts">
        <%= render @microposts %>
      </ol>
      <%= will_paginate @microposts %>
    <% end %>
  </div>
</div>

在 micropost/_micropost.html.erb

<li id="micropost-<%= micropost.id %>">
  <span class="user">
    <%= link_to micropost.user.name, micropost.user %>
  </span>
  <span class="content">
    <%= micropost.content %>
    <%= image_tag micropost.picture.url if micropost.picture? %>
  </span>
  <span class="timestamp">
    <span class="timeago" title=<%= micropost.created_at %>></span>
  <% if current_user.current_user?(micropost.user) %>
    <%= link_to t(".delete"), micropost, method: :delete,
      data: { confirm: t(".confirm") } %>
  <% end %>
  </span>
</li>

而且我会警告动态渲染路径和高亮<%= render @microposts %>。我怎样才能修复它以通过brakenman ?

这是确切的错误:

Render path contains parameter value near line 15: render(action => User.find_by(:id => params[:id]).microposts.order_micropost.paginate(:page => params[:page]), {})
4

2 回答 2

4

这是brakeman 的一个已知问题,如果您只想让代码通过brakeman,您可以更改<%= render @microposts %><%= render partial: 'micropost', :collection => @microposts %>.

来源:https ://github.com/presidentbeef/brakeman/pull/529

于 2018-01-09T17:13:06.867 回答
0

不需要partialcollection就我而言,我改变了:

render @attendance

render "attendances/attendance", attendance: @attendance
于 2021-10-02T07:25:47.357 回答