Rails Model.where how do I get ID? -


i have following statement:

      <% location = location.where('locname' == client.locname) %> 

how .id of location record found?

this didn't work:

      <% location = location.where('locname' == client.locname).id %> 

thanks help!

<% location = location.where("locname = ?", client.locname).first.id %> 

the reason where return activerecord::relation, can either loop through elements or grab first 1 did above.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -