【发布时间】:2014-06-03 01:52:06
【问题描述】:
我正在关注一个视频系列,作者正在使用 RoR 4 创建一个简单的 CMS,但我目前安装了 RoR 3.x。我将所有代码都添加到“T”,但是当我尝试在简单的 CMS 中创建一个简单的主题时,我收到了一个错误。所以我检查了日志/production.log
我收到以下错误,
TypeError (no implicit conversion of Symbol into String):
控制器代码如下所示,
def create
# Instantiate a new object using form parameters
# the below line should work with rails v3.x
# @subject = Subject.new(params[:subject])
@subject = Subject.new(subject_params)
# Save the object
if @subject.save
# add flash hash
flash[:notice] = "Subject created successfully."
# if save succeeds, redirect to the index action
redirect_to(:action => 'index')
else
# if save fails, redisplay the form so user can fix problems
render('new')
end
end
我为主题新参数创建的私有方法如下所示
private
def subject_params
# same as using "params[:subject]", except that it:
# - raises an error if :subject is not present
# - allows listed attributes to be mass-assigned
params.require(:subject).permit(:name, :position, :visible)
end
【问题讨论】:
-
请提供有关错误的更多详细信息。哪个文件,什么行……等等?
-
我们肯定需要回溯的完整错误。
-
我回家后将
subjects_controller.rb转为ghostbin。 -
你已经发布了控制器 - 我们想要错误。
-
@sevenseacat 我如何通过回溯获得完整的错误?
标签: ruby-on-rails ruby ruby-on-rails-4 ruby-on-rails-3.2