Search code examples
ruby-on-railsrubyrails-for-zombies

Rails for Zombies Lab 4 > Exercise 3



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

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.


Solution

  • def create
       @zombie = Zombie.create(params[:zombie])
       redirect_to @zombie
    end