Solved

RoR Find using Conditions, or find_by_sql?

Posted on 2008-10-15
1
1,219 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
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Article by: narshlob
If you've ever programmed in Ruby and have come across either a proc or a lambda, you might have been wondering what the difference is between the two and when you would use one over the other. This article will try to explain the difference between…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now