?
Solved

RoR Find using Conditions, or find_by_sql?

Posted on 2008-10-15
1
Medium Priority
?
1,249 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 2000 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

840 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