Ruby on Rails Simple_form_for的未定义方法

问题描述 投票:1回答:1

我在Ruby on Rails项目的创建视图中遇到了很多麻烦。该模型称为grouponepage。

这是我的new.html.erb:

<%= simple_form_for @postings1314 do |r| %>
  <div>
    <%[email protected] :firstName%>
    <%[email protected]_field :firstName%>
  </div>

  <div>
    <%[email protected] :lastName%>
    <%[email protected]_field :lastName%>
  </div>

  <div>
    <%[email protected] :age%>
    <%[email protected]_field :age%>
  </div>

  <div>
    <%[email protected] :bio%>
    <%[email protected]_field :bio%>
  </div>

  <div>
    <%= @postings1314.submit %>
  </div>
<%end%>

这是我的grouponepostings_controller.rb:

class GrouponepostingsController < ApplicationController
  def index
    @postings1314 = Grouponepage.all
  end
  def show
    @posting1314singular = Grouponepage.find(params[:id])
  end
  def new
    @postings1314 = Grouponepage.new
  end
end

最后,只有在渲染视图时才会出现错误,显示:

Users/______/Desktop/TeenRecuiter/app/views/grouponepostings/new.html.erb where line #1 raised:
undefined method `simple_form_for' for #<#<Class:0x007f9de8119850>:0x007f9de6fc4ca8>
ruby-on-rails ruby database webforms web
1个回答
1
投票

我想你需要添加这个宝石https://github.com/plataformatec/simple_form

将它添加到您的Gemfile:

gem 'simple_form'

运行以下命令进行安装:

bundle install

运行发电机:

rails generate simple_form:install
© www.soinside.com 2019 - 2024. All rights reserved.