top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Is find() a class method or instance method in Ruby on Rails?

+3 votes
467 views

In the following code -

 require 'active_record'

 class Order < ActiveRecord::Base
 end

 order = Order.find(1)
 ...

As per http://api.rubyonrails.org/ find() is an instance public method. So why can we call Order.find(1) here? Shouldn't it be Order.new.find(1)?

posted Jan 6, 2014 by Tarun Singhal

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
+1 vote

When setting the class static variables, These are shared across all the instances created.

Class A
 @@bool_var = true

 def get_bool_var
 @@bool_var
 end
end

All the instances will have this static variable, When through a controller, a user requests, Based on some logic, I set the value to false.

Is this class static variable be set to false in all the other requests from other users on a web application ?

+5 votes

I want to make just simple back End to my first Ruby application, so I want to make header and include it to all of the pages in this back end

So how I can make require or include to simple Html page in ruby (this page just I want to set some links in it)

in Php we just make page and require or include it by
require("my_page_name.php")
or
include("my_page_name.php")

How we can make that in Ruby on Rails.

+1 vote

We recently looked at mongoDB a bit. I was discussing using mongoDB with active record but was told that maybe there are other or better options. Can someone comment on that ?

Also, someone suggested storing a ruby array directly inside of a record where I would have opted for the array to be a separate set of records in active record using has_many and belongs_to .. It seemed to me that how I search on those child records would be a big factor but I soon realized I need to find out what are the options. Do people store arrays and hashes directly in mongo DB fields or is that not the best way to go ?

+1 vote

Something like x.instance_variables.each.... { |i} .... }

Thought to be a one liner. I can't figure out how to apply strip() to each variable, since instance_variable_get returns the value. I really want something I can apply .strip! to....

...