Ruby on Rails syntax question

I am super new to RoR. I am currently working on these interesting Rails exercises for Zombies. And I'm stuck on some syntax issues ...

My code is:

Weapon.where(:zombie => "Ash")

But that will not work. If instead I typed:

Weapon.find(1)

I passed (since the first weapon belongs to the zombie Ash).

My question is: what happened to my answer using this .where () method?

Thanks in advance.

alt text

alt text

alt text

+5
source share
14 answers

You should have enclosed the request as follows:

Weapon.where(:zombie => {:name => "Ash"})

This will give you a zombie weapon whose name is "Ash"

+8
source

, , Zombie Model, first. , where() Zombies.

.

Zombie.where(:name => "Ash").first.weapons

- , , Ruby 1.9 ( ) . Zombies:

Zombie.where(name:"Ash").first.weapons
+4

, where ,

Zombie.where(:name => "ash").first
+3

, Rails3, : zombie, , .

Zombie.where(:name => "Ash").weapons

+2

Model.find( ), , nil, . Model.where({:field => value}) , .

+2

( )

ash = Zombie.find(1) ash.weapons

. count, , (// , ++ python)

+2

, . , API 2010 , , :

Weapon.joi­ns(:zombie­).where(:z­ombies => {:nam­e => "Ash"­})

, , , - , :

Zombie.whe­re(:name => 'Ash'­).first.we­apons
+2

, : Zombie.find(1).weapons.all

FYI - Zombie ID 1 =

+1

Weapon.where(: zombie_id = > '1') = > [#]

+1
Zombie.where(:name => "Ash").first.weapons

: , : -, , - .

, zombie id (Weapon.where(: zombie_id = > SOME_ZOMBIE_ID)), - , - .

ps: , - (. ) - :)

+1

:

z = Zombie.find("ID")
Weapon.where(:zombie_id => z)
+1
Weapon.whe­re(:zombie­_id => Zombi­e.where(:n­ame => "Ash"­))

DB Weapon, zombie_id, - Ash DB Zombie.

+1

, Weapon.find(1), , , : id = > 1, , .

Zombie.find(1).weapons, , : id = 1, , , : name, : id.

"where", - @edgerunner, :

#<ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: zombie.name: SELECT "weapons".* FROM "weapons" WHERE "zombie"."name" = 'Ash'>

so I'm not sure if this is a limitation through the program or what - as it is, I'm still a little confused.

0
source

answers Zombie.find(1).weapons.. then you will be able to find all the weapons Ash.

0
source

All Articles