如何解决“ StaticPages主页中的参数错误”问题

时间:2019-04-11 10:02:55

标签: ruby-on-rails ruby

我在RoR 5.2中安装了我的应用,但收到错误消息:

ArgumentError in StaticPages#home
wrong number of arguments (given 0, expected 1) 

此代码错误的第一行出现:

<% if @feed_items.any? %>
  <ol class="microposts">
    <%= render @feed_items %>
  </ol>
  <%= will_paginate @feed_items %>
<% end %>

当我转到“主页”页面时出现此错误,并且代码在这里:

<div class="col-md-8">
  <h3>Micropost Feed</h3>
  <%= render 'shared/feed' %>
</div>

我也在我的项目目录中搜索了涉及此实例变量'@feed_items'的项目,它位于此处:

  1. static_pages控制器:
      def home
        if logged_in?
          @micropost  = current_user.microposts.build
          @feed_items = current_user.feed.paginate(page: params[:page])
        end
      end
  1. microposts_contoller
     def create
        @micropost = current_user.microposts.build(micropost_params)
        if @micropost.save
          flash[:success] = "Micropost created!"
          redirect_to root_url
        else
          @feed_items = []
          render 'static_pages/home'
        end
      end

此处完全错误:

ActionView::Template::Error (wrong number of arguments (given 0, expected 1)):
    1: <% if @feed_items.any? %>
    2:   <ol class="microposts">
    3:     <%= render @feed_items %>
    4:   </ol>

app/views/shared/_feed.html.erb:1:in `_app_views_shared__feed_html_erb___1043087479159467025_70076005316480'
app/views/static_pages/home.html.erb:13:in `_app_views_static_pages_home_html_erb___2235203620896870682_70076015548660'

预先感谢

0 个答案:

没有答案