search for: const_get

Displaying 20 results from an estimated 62 matches for "const_get".

2006 Apr 05
9
Is eval the only way?
Hi, I''m trying to write some methods which use a parameter to represent a Class name. A very simplistic example: def foo(class_name, conditions) x = class_name.find(:all, :conditions => "#{conditions}") end Unfortunately, this does not work. The only way around this problem that I can think of is to use eval: def foo(class_name, conditions) x = eval
2012 Sep 13
0
Updates to const_get
HELLO other Rails-Core people! I''m trying to push changes to const_get in to ruby-core that will make our lives easier. I''ve pushed a branch of Ruby to github. Can you please check it out to make sure it does what we need? Here is the link: https://github.com/tenderlove/ruby/tree/p2c When we''re happy with the way it works, I''ll do the...
2007 Mar 21
2
store_class_name for Comatose:Page model
...omatose::Page, Article and Product. In all of them, store_class_name is set to true. Now, when i do: results = Comatose::Page.multi_search("*", [Article,Product], options) I get: wrong constant name Comatose::Page #{RAILS_ROOT}/vendor/plugins/acts_as_ferret/lib/class_methods.rb:438:in `const_get'' #{RAILS_ROOT}/vendor/plugins/acts_as_ferret/lib/class_methods.rb:438:in `multi_search'' #{RAILS_ROOT}/vendor/plugins/acts_as_ferret/lib/class_methods.rb:460:in `id_multi_search'' #{RAILS_ROOT}/vendor/plugins/acts_as_ferret/lib/multi_index.rb:28:in `search_each'' #{...
2007 Nov 18
2
Variable inside of another variable
Hi everyone, I''m building partial and I need to use a variable inside of another variable name: I''ve tried like this: <div class="form_row"> <label for="<%= field %>"><%= field_title || field.humanize %>:</ label> <%= form.text_field field, :size => User::field.upcase_SIZE,
2006 Mar 15
4
[NQ] How to set an initial FK for a new item of something?
Hi all, running into a little problem here. I''ve a list of things with a "New thing" link beneath it. When you click that link, obviously, a new thing shall be created. Now, that works pretty fine for things that don''t have foreign keys, but for things that do it crashes, since there is not yet a thing.other_thing.name available. I suspect you can somewhere in
2006 Oct 05
4
search results autocompletion
...| terms = self.all_terms(kl) terms.each{|term| suggestion = Suggestion.new suggestion.term = term SUGGESTION_INDEX << suggestion.to_doc } } SUGGESTION_INDEX.optimize end def self.all_terms(klass) reader = Index::IndexReader.new(Object.const_get(klass.name.upcase + "_INDEX_DIR")) terms = [] begin reader.field_names.each {|field_name| term_enum = reader.terms(field_name) begin term = term_enum.term() if !term.nil? if klass::SUGGESTIONABLE_FIELDS.include?(field_name)...
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
2006 Oct 09
7
multi_search problems, Never go away!
Hello, I am trying to use the multi_search method, but I keep getting type error on nil objects, I send it [Model1,Model2] and it seems as though the class names keep getting clobbered and turn to nil, somewhere along the multi_index area. I tried to trace what was going on, but I got nothing, also, this only happens when there are actually hits(thank god, most of the time). Perhaps some insight?
2006 Dec 30
0
[809] trunk/wxsugar/lib/wx_sugar/layout.rb: Fix default sizers to arrange_vertically, add padding on specified sides
...gt;+ </ins><span class="cx"> def hints_to_constants(layout_hints) </span><del>- layout = Wx::ALL - </del><ins>+ if layout_hints[:pad] + layout = layout_hints[:pad].split('','').inject(0) do | l, edge | + l | Wx::const_get(edge.upcase) + end + else + layout = Wx::ALL + end + </ins><span class="cx"> if layout_hints[:minsize] </span><span class="cx"> layout = layout | Wx::ADJUST_MINSIZE|Wx::EXPAND </span><span class="cx"> en...
2005 Apr 06
3
NameError in <controller not set>#<action not set>
...unities_controller.rb:1 script/server:48 Show framework trace /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.0.3/lib/active_support/dependencies.rb:181:in `const_missing'' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.0.3/lib/active_support/core_ext/string/../../inflector.rb:53:in `const_get'' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.0.3/lib/active_support/core_ext/string/../../inflector.rb:53:in `constantize'' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.0.3/lib/active_support/core_ext/string/../../inflector.rb:52:in `inject'' /usr/local/lib/ruby/...
2006 May 08
0
Including common code among multiple web services issue?
...here... end class WebService < ActionWebService::Base def find_newer_than(created_at) real_class.find(:all, :conditions => [''created_at >= ?'', TimeZone[''London''].unadjust(created_at)]) end ... def real_class Class.const_get(self.class.to_s.gsub(/Service$/, '''')) end ... end ---------------------------------------------------------------------------------- I''d like to do the same for the API''s, but can''t quite get there. If I try the same logic as above then when I go to...
2006 Oct 10
2
Ferret returning too many results
...;m googling like mad, and going through both the source and the forums, and having trouble finding what could be causing this. any help greatly apreciated. relevant code from our rails app: # search_array hold an array of the model we want to search search_array.each do |asset| a = Object.const_get(asset) assets << (a.find_id_by_contents q, :limit => num_docs, :offset => first_doc) end assets.flatten! return assets -- Posted via http://www.ruby-forum.com/.
2005 Aug 16
1
Defining model classes for enumerations
...f class_name.empty? order = spec[:order] || ''position'' table_name = spec[:table_name] || class_name else class_name = spec end module_eval("class #{class_name} < BoilerPlate::EnumRecord; end") enum_class = const_get(class_name) enum_class.table_name = table_name enum_class.preload(:order => order) # mixed-in somewhere else end end end Used like this in, say, environment.rb EnumRecord::define_enums( ''Status'', {:class_name => ''Criterion''...
2006 Jan 20
1
stack level too deep from has_many / belongs_to relationship
...`has_many'' #{RAILS_ROOT}/app/models/routine.rb:2 #{RAILS_ROOT}/app/models/routine_exercise.rb:5 #{RAILS_ROOT}/app/models/routine.rb:2 ... snip ... #{RAILS_ROOT}/app/models/routine_exercise.rb:5 #{RAILS_ROOT}/app/models/routine.rb:2 #{RAILS_ROOT}/app/controllers/items_controller.rb:462:in `const_get'' #{RAILS_ROOT}/app/controllers/items_controller.rb:462:in `item_class'' #{RAILS_ROOT}/app/controllers/items_controller.rb:112:in `new'' So this seems to be getting into a recursive loop around the RoutineExercise belonging to Routine and Routine having many RoutineExerc...
2009 Dec 30
4
Error running Mongrel on Ruby 1.9
...esupport-2.3.5/lib/active_support/dependencies.rb:156:in `require''<br> from C:/Ruby19/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/handler/mongrel.rb:1:in `&lt;top (required)&gt;''<br> from C:/Ruby19/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/handler.rb:17:in `const_get''<br> from C:/Ruby19/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/handler.rb:17:in `block in get''<br> from C:/Ruby19/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/handler.rb:17:in `each''<br> from C:/Ruby19/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/handl...
2006 Jan 19
4
create an object from a string?
I''m trying to dynamically create an instance of an object at runtime, from a String. I have a method that returns one of a number of Strings ("Car", "Motorcycle", "Bicycle"), and when I receive the String, I then want to instantiate one of those objects. Seems like there should be a way to do it in Ruby, but maybe I''ve been up too long --
2006 Jun 08
3
Macros and stuff
...he edit/create/update/new for each are practically identical. So first I DRY''d the four methods in each controller to just one and then I decided to write a single macro for all my controllers. This is the macro: def self.edit_action_for(model, options = {}) model_class = Object.const_get(model) define_method(:edit) do edit_code = lambda do @thing = model_class.find_by_id(params[:id]) || model_class.new if request.post? @thing.attributes = params[:impactable_area] if @thing.save flash[:notice] = "#{model.humanize} succes...
2008 Jan 29
4
Setting up release-1.0.1
...ms/activesupport-2.0.1/lib/active_support/dependencies.rb:453:in `const_missing'' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/dependencies.rb:465:in `const_missing'' from RAILS_HOME/vendor/plugins/backgroundrb/framework/packet_master.rb:96:in `const_get'' from RAILS_HOME/vendor/plugins/backgroundrb/framework/packet_master.rb:96:in `load_workers'' from RAILS_HOME/vendor/plugins/backgroundrb/framework/packet_master.rb:93:in `each'' from RAILS_HOME/vendor/plugins/backgroundrb/framework/packet_master.rb:93:in `load_wor...
2005 Dec 21
1
Table called applications - causes stack overflow?
...ems/activesupport-1.2.4/lib/active_support/dependencies. rb:80:in `const_load!'' ... /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.4/lib/active_support/dependencies. rb:72:in `const_missing'' /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.4/lib/active_support/dependencies. rb:189:in `const_get'' /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.4/lib/active_support/dependencies. rb:189:in `const_missing'' /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.4/lib/active_support/core_ext/stri ng/../../inflector.rb:149:in `module_eval'' /usr/lib/ruby/gems/1.8/gems/activesuppor...
2006 Sep 04
2
"include" versus "extend" - what's the difference
...end def write_audit(action = :update) logger.debug "ACTS AS: write_audit" logger.debug "ACTS AS: self.audited_user_class_name = #{self.audited_user_class_name}" #logger.debug "ACTS AS: Object.const_get(audited_user_class_name) = #{Object.const_get(audited_user_class_name)}" logger.debug "ACTS AS: self.audited_user_method = #{self.audited_user_method}" user = self.audited_user_class_name ? Object.const_get(audited_user_class_name).send(self.audited_...