Jump to content

The ultimate community for Ruby on Rails developers.


Photo

help with syntax with .where and using a method

.where variables

  • Please log in to reply
No replies to this topic

#1 Ola

Ola

    Passenger

  • Members
  • 2 posts

Posted 26 July 2014 - 12:48 AM

Hi,

 

I am trying to find the emails (of all emails) to be equal to the @contact.primary email (so that i can display specific emails in my view)

---

if i hard code the email "jerry@gmail.com", it works the Controller statement below works but if i pass  @contact.primary_email_address  , it does not return anything (it does not error off).  

in my rails c, I can see the Contact has an email address

 

Is the syntax correct on the .where?  

 

 

CONTROLLER 

 

@emails = @account.messages.where(email: @contact.primary_email_address) 

 

  def load_contact

    @contact = Contact.find(params[:id])
  end
 
MODEL
 
  def primary_email_address
    if email = email_addresses.where("email_type = ?", "Primary").first
      email
    else
      email_addresses.first
    end
  end
  end

 







Also tagged with one or more of these keywords: .where, variables

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users