search for: somemodel

Displaying 20 results from an estimated 26 matches for "somemodel".

2009 Aug 19
2
Create! Syntax
...tween create and create! I see that create is document in the api http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002269 What is the difference between the two of these functions and where is the create! function defined. Also, What are the differences between these two calls? a) SomeModel.create!{ :property_a => ''value'', :property_b => ''value 2'' } b) SomeModel.create!({ :property_a => ''value'', :property_b => ''value 2'' }) Thanks a lot for the help! -Jim --~--~---------~--~----~------------~------...
2008 Mar 03
1
Rspec and plugins
I have a question regarding best practices around module and plugin testing for rails applications. In our application we have created several plugins that extend ActiveRecord::Base with class methods, that when invoked in a model add behavior to that model. For example ... class SomeModel < ActiveRecord::Base adds_some_cool_behavior adds_another_wicked_sweet_behavior end My initial thoughts are that any model that add these behaviors "should" have this specified in their spec. With that in mind, I was leaning towards creating a module that when included inside...
2006 Jul 12
1
When to use Mutex::synchronize?
I have a simple question when to the synchronize method in the Mutex class. Now that backgroundrb has allow_concurrency = true there is no need to synchronize database calls in threads. The question I have is lets say I have a simple method in my worker as follows: def some_method SomeModel.find_all each do |obj| obj.some_count += 1 obj.save! end end It accesses the database, but is not in a thread. Since this is a single process running in the background, if that method gets called simultaneously will the database lose connection? Will I get unexpected results? For instan...
2006 Feb 07
4
Ruby, Rails & Inheritance
...---------------------------------------------- class RecordWithFeatures < ActiveRecord::Base # @Override def self.descends_from_active_record? superclass == RecordWithFeatures end # @Override def self.class_name_of_active_record_descendant(klass) ... end ... end class SomeModel < RecordWithFeatures ... end ----------------------------------------------------------------- Ok, everything works fine, but I would also like to pass some class-methods to my models as soon as the inherit RecordWithFeatures. Example: All models have an attribute "context_id", so ev...
2006 Jan 11
2
How to execute an SQL statement in rails?
Hello, This is probably a silly question but looking at "api.rubyonrails.org", I can''t seem to figure out which method I should be using ... I want to execute an sql statement, like "truncate table BLAH" from within one of my rails app ... What''s the "right" way to do this? Thanks, /B -- Bruno Mattarollo <bruno.mattarollo@gmail.com>
2006 Jul 05
10
Scalable alternative to #find_all
Is there any scalable alternative to iterating all the records of a certain model? #find_all seems to load everything into memory. With 500.000 records it will be a swap storm. Pedro.
2006 Jun 26
1
Separate Read and Write Database
Hello, I need to access an mirrored database with one read and one write cluster. Is there a way to tell a model to use two connections? So that all updates etc go to the write database and all read from the read one? This is a fixed set up I can not use MySQL 5.x stuff and additionally i get a token on write, which can be checked on read (and wait for replication) if new data is needed. I
2006 Feb 16
10
Ruby class variables and access from view templates
...a controller and then access it from within a view. It seems that the class variables aren''t working right. Here is an example of what I''m trying to do. class DisplayController < ApplicationController @@thumbnail_array = Array.new ... def some_method @@thumbnail_array = SomeModel.find_all ... end ..... end Then in the view for some_method, <% for thumb in @@thumbnail_array %> ... do something interesting But my app blows up at that point giving me an unitialized class variable - @@thumbnail_array. What am I doing wrong? -- Posted via http://www.ruby-forum.com...
2006 Feb 08
3
Extends ActiveRecord from the application ?
Hello, I just want to create a method that will be available for all models. Is it possible ?
2006 Apr 07
3
List of all Models
Anyone know a pretty way to get a list of all Models? That is, a list of all classes which inherit from ActiveRecord:Base I can''t seem to figure it out! The best I''ve got is to list the /app/models directory... but, that is *dirty*. -hampton. -------------- next part -------------- An HTML attachment was scrubbed... URL:
2006 Feb 15
2
extending rails via /lib - problems
...helpers but I couldn''t find anything about models. Using the /lib directory seemed to be the only way. Alright... so I have something like this: /lib/code.rb class ActiveRecord::Base def method_a(n) ....... end def method_b(n) ........ end end /models/some_model.rb class SomeModel < ActiveRecord::Base def self.some_method(a, b) ........ end def other_method ........ end end I also added `require ''code''` to enviroment.rb My problem is that, for some reason, I can''t use any method declared in code.rb inside `self.some_method`. Howe...
2006 May 08
4
rake db:migrate
Would it make sense for rake db:migrate to support creating databases if it is not found, with blessing from user to prevent typos, or as an additional command line switch. Or am I just being too lazy? -- Posted via http://www.ruby-forum.com/.
2006 Nov 17
4
before_destroy and sessions
(Semi-newbie.) I want to ensure a user''s able to destroy only his own objects. I''ve set session info at login: session[:user_id] = user.id Now I try this in the model of my deletable objects: before_destroy :destroy_your_own def destroy_your_own raise "Can''t delete that!" unless session[:user_id] == self.user.id end which snags EVERY attempted
2007 Nov 07
7
Help on loop
Hey, I have got a script that returns a long list of font family names, which I all want to store in a variable (array). I tried doing this with @f = font.family also in the for loop below but it only prints the last item when I want to display the results. require ''rubygems'' require ''RMagick'' include Magick for font in Magick.fonts puts font.family end
2012 Sep 11
3
question about how to set up an active record adapter to prefer use of prepared statements...
Hi, I am writing an active record adapter for our new database and when I run the tests I see lots of statements that could be run as prepared statements, but instead of passing me bindings AR passes me a fully specialized SQL string, not in all cases, but in many. Here is an example: SELECT addrs.* FROM addrs WHERE addrs.user_id = 153 FETCH FIRST 1 ROWS ONLY I do have this hook set up:
2005 Dec 31
7
Dynamic form? Not really!
Hi guru''s out there, Im happilly coding my first rails app, and all goes well. I find myself manually coding in a particular field all the time (company_id), that relates the contact to a company. The total coding of this form seems somewhat much. Could somebody tell me what Rails power I''m possibly missing and stuborn as I am trying to do myself? I was wondering if the
2006 May 05
7
vim: space or tab in indenting?
this is semi-off topic but still related to ror. i had a problem with testing my depot program (which i follow the tutorial in agile web development book). it took me many hours to solved the problem. all the while i thought i was using spaces inside the test/fixtures/products.yml programmer_book: id: 1 title: Pragmatic Programmer description: Best book
2006 Apr 14
5
One Controller, Many models
Hello all, I am working on a app right now that is going to replace a paper form process out client has. This process has quite a few forms (about 30) and different groups of forms (section) need to be filled out based on what information is required from the user. For example, here is a possible process of 2 users: user 1 user 2 Section 1 Section 1 Section 2 Section 2
2008 Jul 02
2
How to write the method before_destroy and the test
How to write the method before_destroy? Here is my code: def before_destroy errors.add(:isdefault,"Can''t destroy default record") if self.isdefault return false end or I should write it like below? def before_destroy raise(Can''t destroy default record") if self.isdefault end and how to write the test for it -- Posted via
2005 Nov 25
4
Set default order for find(:all) in a model
Hi everyone Is there a way that I can get the find(:all) method to return in a specified order, without including the :order argument every time? Guess I just don''t like typing... Cheers _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails