Ruby on Rails Simple_form_for的未定义方法

时间:2022-09-04 08:55:11

I have been facing a lot of troubles with the create view for my Ruby on Rails project. The model is called grouponepage.

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

Here is my new.html.erb:

这是我的new.html.erb:

<%= simple_form_for @postings1314 do |r| %>
  <div>
    <%=@postings1314.label :firstName%>
    <%=@postings1314.text_field :firstName%>
  </div>

  <div>
    <%=@postings1314.label :lastName%>
    <%=@postings1314.text_field :lastName%>
  </div>

  <div>
    <%=@postings1314.label :age%>
    <%=@postings1314.text_field :age%>
  </div>

  <div>
    <%=@postings1314.label :bio%>
    <%=@postings1314.text_field :bio%>
  </div>

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

This is my grouponepostings_controller.rb:

这是我的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

And finally, the error occurs only when the view is rendered, showing:

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

Users/______/Desktop/TeenRecuiter/app/views/grouponepostings/new.html.erb where line #1 raised:
undefined method `simple_form_for' for #<#<Class:0x007f9de8119850>:0x007f9de6fc4ca8>

1 个解决方案

#1


-1  

I guess you need add this gem https://github.com/plataformatec/simple_form

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

Add it to your Gemfile:

将它添加到您的Gemfile:

gem 'simple_form'

Run the following command to install it:

运行以下命令进行安装:

bundle install

Run the generator:

运行发电机:

rails generate simple_form:install

#1


-1  

I guess you need add this gem https://github.com/plataformatec/simple_form

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

Add it to your Gemfile:

将它添加到您的Gemfile:

gem 'simple_form'

Run the following command to install it:

运行以下命令进行安装:

bundle install

Run the generator:

运行发电机:

rails generate simple_form:install