Solved

RoR Find using Conditions, or find_by_sql?

Posted on 2008-10-15
1
1,226 Views
Last Modified: 2013-11-13
Hi, im trying to query my database and am passing a type variable with value "Hardware", a manufacturer variable with value of "Dell and an invoice variable with value of "SI11244"

Here is the url im putting into my browser:
http://localhost:3000/assets/findbyparams?manufacturer=Dell&type=Hardware&invoice=SI11244

i have a findbyparams method in my controller but have no idea how to put these values into a find statement to return the aassets where the TYPE column equals "Hardware, the MANUFACTURER column equals "Dell" and INVOICE column equals "SI11244"

thanks
0
Comment
Question by:Jonesey007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 14

Accepted Solution

by:
wesgarrison earned 500 total points
ID: 22727750

def find
  @type = params[:type]
  @manuf = params[:manufacturer]
  @invoice = params[:invoice]
  
  @assets = Asset.find_all_by_type_and_manufacturer_and_invoice(@type, @manuf, @invoice)
  @assets = Asset.find(:all, :conditions => ["type = ? and manufacturer = 
? and invoice = ?", @type, @manuf, @invoice])
end
 
# both should return the same thing

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently rediscovered rails when I needed a holiday project and decided to build a management dashboard for the company where I work.  With it being a project done in my free time, I could focus my time on learning the basics rather than trying to…
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question