【发布时间】:2015-11-27 21:14:04
【问题描述】:
我在 ruby on rails 上遇到 simple_form gem 的问题。我正在使用一个实例变量,但是当我在部分声明它时,它出现“WelcomePageController:Class 的未定义方法‘model_name’”我不知道发生了什么。我试图解决它,但它对我来说是不可能的
这是我的控制器页面
class WelcomePageController < ApplicationController
def index
end
def new
@neword = WelcomePageController.new
end
def create
@neword = WelcomePageController.new(words_params)
end
private
def words_params
params.require(:words_input).permit(:word, :definition, :example)
end
end
这是我的部分表格
<%= simple_form_for @neword do |f| %>
<%= f. input :word, label: "insert a word"%>
<%= f. text :definition, label: "give a definition" %>
<%= f.text :example, label: "give an exmaple" %>
<%= f. button :submit %>
<% end %>
这是我的新观点
<h1>hi, again</h1>
<%= render 'form' %>
希望你能帮帮我:)
【问题讨论】:
-
你传递给
simple_form_for的对象应该是一个模型,你定义的实例变量是一个控制器。
标签: ruby-on-rails ruby methods undefined simple-form