僵尸实验室4的Rails>练习3 [英] Rails for Zombies Lab 4 > Exercise 3
本文介绍了僵尸实验室4的Rails>练习3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在第三次练习中,我陷入了僵尸的第四个Rails实验室.这是我的任务:创建动作,该动作将创建一个新的僵尸,然后重定向到创建的僵尸的显示页面.
我有以下参数数组:
I stucked in the fourth Rails for Zombies lab at the third exercise. This is my task: Create action that will create a new Zombie and then redirect to the created zombie's show page.
I've got the following params array:
params = { :zombie => { :name => "Greg", :graveyard => "TBA" } }
我编写了以下代码作为解决方案:
I wrote the following code as a solution:
def create
@zombie = Zombie.create
@zombie.name = params[ :zombie [ :name ] ]
@zombie.graveyard = params[ :zombie [ :graveyard ] ]
@zombie.save
redirect_to(create_zombie_path)
end
但是当我提交它时,出现以下错误:
#<TypeError: can't convert Symbol into Integer>
But when I submit it I got the following error:
#<TypeError: can't convert Symbol into Integer>
我知道我犯了一个错误,但我不知道在哪里.请帮助我.
I know that I made a mistake but I cannot figure out where. Please help me.
推荐答案
def create
@zombie = Zombie.create(params[:zombie])
redirect_to @zombie
end
这篇关于僵尸实验室4的Rails>练习3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文