Skip to content
Advertisement

Ruby on Rails Database Query with Ruby Variable

This is the current code for my query..

I want to be able to add something like

But everything I try doesn’t seem to work due to the “property_id” portion. I’ve tried concatenating, different assignments, etc. I feel dumb. SOS. Thank you ahead of time.

Also, when I add..

Which “hotelid1” is an existing hotel_id in the table. It works but not how I would imagine. It returns..

I’m wanting it to only output the hotel name. In this case, HotelOne.

Advertisement

Answer

ActiveRecord’s where should be suffice for you.

And it’s confusing to have hotel_id in Hotel model as it contradicts with the default id attribute. Anyhow hope this was useful to you.

Note: If hotel_id is unique in your table then better to go with @SebastianPalma‘s comment in your question.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement