gpt4 book ai didi

ruby-on-rails - Ruby on Rails 未定义的 simple_form_for 方法

转载 作者:搜寻专家 更新时间:2023-10-30 23:28:59 27 4
gpt4 key购买 nike

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

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

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

最后,错误仅在呈现 View 时发生,显示:

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

最佳答案

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

将其添加到您的 Gemfile 中:

gem 'simple_form'

运行以下命令进行安装:

bundle install

运行生成器:

rails generate simple_form:install

关于ruby-on-rails - Ruby on Rails 未定义的 simple_form_for 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52012839/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com