Search Results

Search found 2229 results on 90 pages for 'conditions'.

Page 36/90 | < Previous Page | 32 33 34 35 36 37 38 39 40 41 42 43  | Next Page >

  • Ruby/Rails - Add records to an object with each loop iteration / Object vs Arrays

    - by ChrisWesAllen
    I'm trying to figure out how to add records to an existing object for each iteration of a loop. I'm having a hard time discovering the difference between an object and an array. I have this @events = Event.find(1) @loops = Choices.find(:all, :limit => 5) #so loop for 5 instances of choice model for loop in @loops @events = Event.find(:all,:conditions => ["event.id = ?", loop.event_id ]) end I'm trying to add a new events to the existing @events object based on the id of whatever the loop variable is. But the ( = ) operator just creates a new instance of the @events object. I tried ( += ) and ( << ) as operators but got the error "You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil" I tried created an array events = [] events << Event.find(1) @loops = Choices.find(:all, :limit => 5) #so loop for 5 instances of choice model for loop in @loops events << Event.find(:all,:conditions => ["event.id = ?", loop.event_id ]) end But I dont know how to call that arrays attributes within the view With objects I was able do create a loop within the view and call all the attributes of that object as well... <table> <% for event in @events %> <tr> <td><%= link_to event.title, event %></td> <td><%= event.start_date %></td> <td><%= event.price %></td> </tr> <% end %> </table> How could i do this with an array set? So the questions are 1) Whats the difference between arrays and objects? 2) Is there a way to add into the existing object for each iteration? 3) If I use an array, is there a way to call the attributes for each array record within the view?

    Read the article

  • Obtaining ActiveRecords if NOT nil

    - by user275729
    I would like to be able to gather all records in a table where the user_id is not null. This is what I have but it doesn't seem to be working (even though I've had it working in a seperate project): named_scope :all_registered, :conditions => ["user_id != ?", nil]

    Read the article

  • list comprehension example

    - by self
    can we use elif in list comprehension? example : l = [1, 2, 3, 4, 5] for values in l: if values==1: print 'yes' elif values==2: print 'no' else: print 'idle' can we use list comprehension for such 2 if conditions and one else condition? foe example answer like : ['yes', 'no', 'idle', 'idle', 'idle'] I have done till now only if else in list comprehension.

    Read the article

  • Passing arguments to scope_procedure in searchlogic

    - by Greg
    I'd like to use searchlogic's scope_procedure feature like so class MyModelObject < ActiveRecord::Base scope_procedure :my_scope_proc, lambda { |p1, p2| { :conditions => "p1 >= #{p1} AND p2 < #{p2}" }} end Then, I am doing the search: scope = MyModelObject.search(:my_scope_proc => true) scope.all The above code obviously doesn't work because I didn't pass p1 and p2 parameters to my named scope. I can't figure out how to pass parameters to the named scope.

    Read the article

  • convert string to double

    - by James123
    I have string value in that I need to convert to double in VB.Net. Conditions are like below string = "12345.00232232" if condition is 3 (2 digits after decimal and comma) display = 12,345.00 if condition is 5 (5 digits after decimal and comma) display = 12,345.00232 If Condition is 7 ( 5 digits after decimal and no comma) display = 12345.00232 How can I do that in VB.Net?

    Read the article

  • How to make Android Service run even when the device is not awake?

    - by Deema
    hi my application objective is to save location updates every ,let say, 20 minuets . I used service and it worked fine , but when i lock the screen or it is locked automatically the service stop running . when i unlock it , service runs again. highlight on my code: Service xxx onCreat(){ call timer(); } timer(){ code } How to make my code run all the time in all conditions?

    Read the article

  • Ruby Module Inclusion in Methods

    - by Federico Builes
    In class Foo I'd like to include method Bar under certain conditions: module Bar def some_method "orly" end end class Foo def initialize(some_condition) if !some_condition "bar" else class << self; include Bar; end end end end Is there any cleaner (and clearer) way to achieve the include in the method without having to do it inside the singleton class?

    Read the article

  • Linear-time algorithms for sorting vertices in polygon contours

    - by Cheery
    I figured out an algorithm that lets me turn my holed polygons into trapezoids in linear time if I have vertex indices sorted from lowest coordinate to highest. I get simple polygons as contours. They have certain order that might be exploited most of the time. So giving these conditions, is there a near-linear-time algorithm on sorting?

    Read the article

  • Does iPhone SDK Objective C support functions inside of functions?

    - by Moshe
    I know that javascript, for example supports functions inside of functions, like so: function doSomething(){ function doAnothingThing(){ //this function is redefined every time doSomething() is called and only exists inside doSomething() } //you can also stick it inside of conditions if(yes){ function doSomethingElse(){ //this function only exists if yes is true } } } Does objective-c support this? Theoretical example: -(void) doSomething:(id) sender{ -(void) respondToEvent: (id) sender{ //theoretically? ... please? } } BONUS: What is the proper term for a "local" function?

    Read the article

  • Does HttpWebRequest automatically take care of certificate validation?

    - by Kevin Pang
    I'm using an HttpWebRequest object to access a web service via an HTTP POST. Part of the requirement is that I: Verify that the URL in the certificate matches the URL I'm posting to Verify that the certificate is valid and trusted Verify that the certificate has not expired Does HttpWebRequest automatically handle that for me? I'd assume that if any of these conditions came up, I'd get the standard "could not establish trust relationship for the SSL/TLS secure channel" exception.

    Read the article

  • add_without_safety create new DB entry in controller

    - by Karl Entwistle
    Im trying to get a controller to create a new account with the user id filled in, this doesn't work in my controller or in the console, why? Any suggestions on how to implement this would be much appreciated. class PaymentNotification < ActiveRecord::Base after_create :add_account_to_market private def add_account_to_market if status == "Completed" line = LineItem.find(:first, :conditions => { :cart_id => cart.id }) line.quantity.times do Account.new(:user_id => cart.user_id) end end end end

    Read the article

  • How do I make all the finders on the model ignorecase?

    - by Glex
    I have a model with several attributes, among them title and artist. The case of title and artist should be ignored in all the Active Record finders. Basically, if title or artist are present in the :conditions (or dynamically i.e. find_all_by_artist), then the WHERE artist = :artist should become WHERE UPPER(artist) = UPPER(:artist) or something along these lines. Is there a way of doing it with Rails?

    Read the article

  • Convert a form_tag select_datetime to SQL datetime

    - by Mitchell
    Hi I am trying to make a simple search form that uses a startTime and endTime to specify a time range. The db has a datetime field time that is compared against. So far when i try to use params[:startTime] in the controller I get an array of values which wont work with :conditions = ['time < ?', params[:endTime]] Is there a simple solution to parse the form's datetime to SQL datetime?

    Read the article

  • cakephp: how to make NOW() work in search condition ?

    - by kaklon
    I'm trying to get all records with date greater then now. I tried this but it doeasnt work: $all_dates = $this->TourDate->find('all', array('conditions' => array('TourDate.date >=' => 'NOW()'), 'order' => array('TourDate.date ASC'))); If I replace NOW() with the current date it works. Why's that?

    Read the article

  • Constructing an if statement from the client data in python

    - by Vishal
    Hi, I need to construct an if statement from the data coming from the client as below: conditions: condition1, condition2, condition3, condition4 logical operators: lo1, lo2, lo3 (Possible values: "and" "or") Eg. if condition1 lo1 condition2 lo3 condition4: # Do something I can think of eval/exec but not sure how safe they are! Any better approach or alternative? Appreciate your responses :) PS: Client-side: Flex, Server-side: Python, over internet Thanks

    Read the article

  • Rails only returns blank page

    - by user2793027
    I am new to Ruby on Rails and am trying to find all the orders for a given customer and then search through their order and total it all up. However when I try and test the page I only get a blank page, can anyone tell me why that might be? Also I am running Rails v. 2.3.14 <% # custdisplay.html.erb.rb %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head profile="http://gmpg.org/xfn/11"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <% # get the customer data from the customer table @custdata = Customer.find(@data) @orderinfo = Order.find(:all, :conditions => ["customer_id = ?",@custdata.id]) for i in [email protected] @total[i] = 0 @orderparts = Orderline.find(:all, :conditions => ["id = ?", @orderinfo[i].id]) for j in [email protected] @total[j] += @orderparts[i].quantity * @orderparts[i].price end end #for each quanity need to add up the part if @ordertotals.length > 0 %> <h1>customer data for customer: <%=@data %></h1> <table border=1> <tr> <td>Order Number</td> <td>Order Date</td> <td>Cost of Order</td> </tr> <% # for each customer who has this sales rep # display each customer in a row for @orderinfo in @ordertotals %> <tr> <td><%[email protected]%></td> <td><%[email protected]_date%></td> <td><%[email protected]%></td> </tr> <% end %> </table> <% else # no customers with this sales rep %> <h1>NO CUSTOMERS FOR SALES REP <%=@salesrepcust%></h1> <% end %>

    Read the article

  • Android Test testPreconditions

    - by user1184113
    In Android developers I've seen that testPreconditions() method is supposed to be launch before all tests. But in my app test, it's acting like a normal test. It does not run before all tests. Is there something wrong ? Here is the description about testPreconditions() from android developer : "A preconditions test checks the initial application conditions prior to executing other tests. It's similar to setUp(), but with less overhead, since it only runs once."

    Read the article

< Previous Page | 32 33 34 35 36 37 38 39 40 41 42 43  | Next Page >