Jump to content

The ultimate community for Ruby on Rails developers.


rails newbie - help with syntax

.where variables syntax controller where

  • Please log in to reply
2 replies to this topic

#1 Ola



  • Members
  • 3 posts

Posted 26 July 2014 - 10:44 AM

hi - any help would be appreciated.  many thanks.


i have this in my controller action 


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



@contact is a defined controller method

  def load_contact
    @contact = Contact.find(params[:id])


primary_email_address is a defined model method 

  def primary_email_address

    if email = email_addresses.where("email_type = ?", "Primary").first
Both of the METHODs work when use in other places.  When you here, it does not seem to be picking up the email
that I am expecting.  Just wondering if the SYNTAX above is correct? 

#2 Javix



  • Members
  • 6 posts

Posted 11 August 2014 - 02:10 PM

What do you mean by 



-  work when use in other places
-When you here, it does not seem to be picking up the email that I am expecting.

Which kind of error do you get (observe log files).

You can also play with that directly in your rails console:

rails c --sandbox

Then run all the necessary steps: find a contact, for ex. take just the first one, then execute all the rest, line by line:

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

By the way, I can't see where the variable @account comes from.

#3 Anuj Dubey

Anuj Dubey


  • Members
  • 6 posts

Posted 23 September 2014 - 12:02 PM

It might be due to there is no relationship between Content model and the email address model.

If the relationaship present then try this.

@contact = Contact.where(id: params[:id]).first

this might work!!!

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

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users