search for: some_method

Displaying 20 results from an estimated 38 matches for "some_method".

2006 Feb 15
2
extending rails via /lib - problems
...ng 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`. However, the methods work perfectly well inside `o...
2009 May 13
2
Object and Classes ?
...! It was short description so I couldn't grok in full its usage ... So far so good, what i currently do is something like this : Blah <- function(data,...) UseMethod('Blah') Blah.default <- function( ...... ) { self = .... class(self) <- 'Blah' self } Blah.some_method <- function(self, .....) { self$abc ......and so on } My main "concerns" is now I have to call methods like this : Blah.some_method(obj,.....) isn't there some more shortcut syntax something along the lines of ;) : obj.some_method(...) Also if you can point me to some m...
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?...
2013 Mar 26
0
nested forms: use validate :some_method works in update mode only
I have a strange behavior when validating a record in a nested form. The association collection is empty when creating a new record and the validation does not catch the error. But when updating the same record the validation gets it right but continues to catch the error even after modifying the needed attribute value to make it pass. Here is the model: #timesheet.rb class Timesheet <
2006 Feb 18
5
Model methods and partial view templates
I have a method in a controller that invokes a render :partial => ''some_partial_view'' In that view, I''m trying to access a method defined in a model, like this; <% for view in @an_array %> <% local_var = view.some_method() %> <% another_var = view.a_column_name %> etc.. I am getting an undefined method error but the model is accessible because the variable ''another_var'' is accessed correctly. I have tried the following definitions in my ''View'' model; def some_meth...
2006 Feb 16
10
Ruby class variables and access from view templates
...variable (actually an array) in 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? -- Post...
2006 Apr 14
5
state_models plugin and file_column?
I was looking at Kyle Mawell''s extremely nifty-looking StateModels plugin http://www.kylemaxwell.com/articles/2006/02/06/fun-with-single-table-inheritance and before I go down the road with it, I was wondering if anyone has used it with file_column. The way file_column deals with an uploaded file -- by storing it to the filesystem in a path that employs the model name and id --
2008 Jan 27
2
conditional validation
Hi, How can I validate user info under certain conditions? For example, I just downloaded a plug-in that allows me to validate phone numbers, but what I would like is to only validate the phone number if it is not blank and if the user_type_id field is equal to one. How can I achieve such a validation in my user model? Thanks, - Dave --~--~---------~--~----~------------~-------~--~----~ You
2006 Jul 25
3
Question about how Mongrel process works with singletons
Hi, I have a controller where I access a singleton class that I use to connect to a DRbprocess DrbConnector.instance.some_method I notice that on every request, the constructor is called so it is making a new instance of this singleton. Is this normal? Thanks, Curtis
2012 Sep 04
5
Associations and Math between Models
...9;'m trying to get an attribute from model_1 to use in a method in model_2. When I use the code below, I get an error saying ''undefined method model_1_id''. What am I missing? Thanks! Model_2.rb Class Model_2 < ActiveRecord::Base ... has_and_belongs_to_many :model_1 def some_method attr_a * Model_1.find(model_1_id).attr_I_need end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from thi...
2006 Jul 14
3
Accessing the Model class from Controller
Hi, I wonder if there''s an easy way to access the associated Model class from its Controller. Something that would allow me to write snippets like the following: class PeopleController < ApplicationController def some_method person_model_class = self.some_method_to_retrieve_the_person_model_class() end end Cheers, Marco -- Posted via http://www.ruby-forum.com/.
2009 Apr 21
2
validates_uniqueness_of
hello all, i am new to RoR programming and am struck with the functional test whole checking for uniqeness of carriers. If it is not unique,the the bin shudn''t be created.Can someone help me in correcting my code. def test_create_failure_cycle_unique begin num_bins = Bin.count post :create, {:bin => { :carrier => carriers(:A), :cycle => cycles(:one), :name =>
2010 Sep 16
3
Resyful authenticatio current_user in model
Hi, I am using Restful authentication for user authentication. I want the current logged in user object in my model property.rb Problem is current_user is not working on model. How can I fix this I need that? Please help me out. Thanks, Mike -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk"
2007 Jun 18
2
weakness of helper?
Hi , It comes to me that helper has some weaknesses: 1) It is hard to test . No easy way to write test code for it. (or Just i didn''t know?) 2) Not easy to reuse it on other controller/view/model. it looks like to that putting the helper code into a model (a fully helper model , or a mixed model) is good practice. However i agree that some html intensive
2013 Jul 09
5
whenever gem
...ay. I used whenever gem. I added gem ''whenever'' in my gemfile. Then in the terminal I did - "whenever ." which created a schedule.rb. In schedule.rd I added this piece of code:- set :environment, "development" every 2.minutes do runner "UserMailer.some_method" end Does it get invoked automatically ? or do I need to do something to invoke it? Thanks, Avi -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an emai...
2006 Jul 19
1
Passing objects to drb, does it keep the existing db connection?
I have a simple question. Let''s say I do this in one of my models: after_save drb_conn.some_method(self) end When that object gets over to the background process is it the exact same as?.... Model.find some_id #in the background process As far as my background process is concerned passing the object is not any different than passing the id and using the find method? Because when I try t...
2006 May 21
1
how do I bypass using the standard layout for a file
Hi, i''m trying dyamically add a bit of code into a page by updating a div. this works great but it puts the page in with the standard layout around it duplicating it. Is there someway just to bypass using any layout with a rhtml file? -- Posted via http://www.ruby-forum.com/.
2006 Jan 20
1
Best way to execute timed actions?
...y, or cleaning up your database or server files. This wiki page has some ideas, but these seem a bit extreme. http://wiki.rubyonrails.com/rails/pages/HowToRunBackgroundJobsInRails I''ve also seen people suggest using cron to execute script/runner: script/runner -e production "Model.some_method()" It seems to me you could also have cron execute a wget to a page like: wget http://www.domain.com/controller/action/id And I vaguely remember someone saying they were working on a better solution (as a plugin?). What are people actually using? What works best? Thanks, Kevin Skoglund
2007 Mar 20
1
Passing Arguments to before_filter
I want to put a before_filter in application.rb, as follows: before_filter :do_something, :except_controller => [:admin] def do_something(options) options.stringify_keys! unless options[:except_controller].include?(controller_name) # do something useful end end Where I''m blocking is on how to get the ''options'' data in the do_something method. I think I
2008 May 30
4
deprecation warnings
I''m still using 1.2.6 and have an eye on upgrading to 2.0 so I monitor the logs for deprecation warnings. I thought I was clean and log/development.log shows nothing when doing ''grep deprec log/development.log'' but in testing, one of my testing controllers throws a bunch of these on screen...