Displaying 20 results from an estimated 200 matches similar to: "define_method vs module_eval"
2012 Sep 09
2
mattr_accessor inside a class
Rails extends Ruby with mattr_accessor (Module accessor). As Ruby''s
attr_accessor generates getter/setter methods for instances,
mattr_accessor provide getter/setter methods at the module level. In
below example, you see that mattr_accessor declared in the class
context of LookupContext. It''s declared in class, not module. However,
modules are defined in LookupContext, for
2008 Jan 13
2
module_eval and scope question
When trying to understand a piece of code from the Ruby-On-Rails
framework,
I found that I''m still lacking knowledge about scope issues in Ruby.
Here is a
stripped down version of the code I''m trying to understand (in case
you
happen to use Rails: This is from file scaffolding.rb):
module ActionController
module Scaffolding
..
module ClassMethods
def
2005 Dec 15
3
define_method with parameters
Hi,
I''m trying to write a macro which defines methods. One of these should
have a parameter, but I can''t get that to work. Something like:
define_method("printstuff") do
puts "blabla"
end
works fine. But, how do I use define_method to create something like:
def printstuff(the_stuff)
puts the_stuff
end
Thanks in advance.
2012 Sep 14
1
calling method on base intended to simulate initialize on instances?
class A
def initialize
setup_b
setup_c
end
def b_and_c
"#{@b} and #{@c}"
end
private
def setup_b
@b = ''b''
end
def setup_c
@c = ''c''
end
def setup_d
@d = ''d''
end
end
a = A.new
a.instance_variable_get("@b") # => "b"
a.instance_variable_get("@c") # =>
2010 Jul 04
2
Rendering a different format in the implementation of a renderer
Yehuda has a nice article on implementing a custom renderer for PDF at
http://www.engineyard.com/blog/2010/render-options-in-rails-3/
I''ve tried to follow the example and I''m not sure I see how to get it to
work. If I understand things correctly, the format(s) usable in this
render call
respond_with(@resource) do |format|
format.xyz { render :xyz => ... }
end
2012 Sep 22
4
Class, Module, Object
>> reload!
Reloading...
=> true
>> puts Class < Module
true
=> nil
>> puts Module < Class
false
=> nil
>> puts Module < Object
true
=> nil
>> puts Object < Module
false
=> nil
>> Object.parent
=> Object
The above indicates that the Class object instance inherits from the
Module object instance and the Module object instance
2006 Aug 01
4
How do you evaluate text as code in Ruby?
How do you evaluate text as code in Ruby?
I''m sure there''s a technical term for this...
Thanks
Chris
--
Posted via http://www.ruby-forum.com/.
2007 May 10
13
Is there a way to do incremental search?
Say the user first enters "ruby" for search and gets 1000 results. Then
he can search "rails" just in the 1000 results just returned.
The common scenario is some kind of advanced search. User can
incrementally add criteria and the program will narrow the results step
by step.
I know that at least I can use all the criteria as a whole to do the
searching, but this is a waste
2006 Jun 08
3
Macros and stuff
I was looking at my controller code and the 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
2006 Mar 13
1
adding custom cache field
Hello,
I needed to add custom cache field for one of my application. I thought I
will share the code showing how to do this.
This code below creates and maintain a custom cache field, for keeping track
of totals. Say, you have accounts, and for each account there are transactions
(either deposit/withdrawal), and one will like to keep track of the total
balance for an account.
So, let there be a
2014 Feb 12
61
P2V: Headless support
This introduces support to run P2V without X server. Runtime parameters
are specified via kernel command line making it hopefully suitable for
automated migration with a little help of PXE boot.
Patchset is not squashed and represents dev. history.
2006 Mar 26
2
Shared Columns in an STI
I have a an STI table which acts_as_tree, that has a large number of
classes/types. My common fields are:
id
parent_id
name
description
with 4 more text fields, I could cover most of my classes if I could
redefine the name of the field like this.
text1 AS address1
text2 AS address2
text3 AS zipcode
For one class and
text 1 AS model_number
text2 AS vendor
Is there a construct that will allow
2006 Jul 22
1
How to debug this
Hello,I get this message and I don''t know how to interprete this.I think it has to do with plural tables and singular referencesThanks for any help!Jim======================================================================================uninitialized constant SubjectRAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace
2006 Jan 09
1
Cooky Cookies
Hi All,
I have a problem with the stemming(?) in rails. I have a table cookie and a
Cookie model which I have generated a scaffold for. The problem is that
rails starts looking for a file that it calls "cooky.rb", this must be some
kind of misunderstanding between me and rails, but how do I correct it?
Other scaffolds work just fine.
/Hugo
NameError in Cookie#index
uninitialized
2006 Jul 26
1
Scaffolding Problems
Hi.. Im a brand new ruby on rails developer, and when i make a scaffold
and navigate to the it, i get an error that looks like this.
-----------------------------------------------------------------
NameError in PagesController#list
uninitialized constant Page
RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace
2007 Aug 10
3
Different ferret fields for instances of the same model?
Hi all,
So far as I know, while using acts_as_ferret, we should add the
following declaration in the ActiveRecord model which is going to be
indexed:
acts_as_ferret({:fields => @@ferrect_fields})
in which @@ferrect_fields is a hash containing all the field to be
indexed. This is pretty much for some simple situations. But I got a
more complex situation that I want to define the fields to be
2006 Jan 10
1
Cooky cookies causes trouble
Hi All,
Yesterday wrote about my troubles with naming a table and model cookies and
cookie respectively. I know that everybody hates the newbie screaming bug as
soon as he encounters behaviour he doesn''t understand. But I''ve reproduced
the error in the simplest application possible, and dare therefore say that
this quite possible could be a bug in Rails.
Database:
CREATE TABLE
2007 Sep 30
2
Outputing to the browser, how?
Hello,
I''m writting some helper methods to write forms, so I have this working code:
class TableFormBuilder < ActionView::Helpers::FormBuilder
["file_field", "password_field", "text_field"].each do |name|
define_method(name) do |label, *args|
@template.content_tag(:tr,
@template.content_tag(:td,
@template.content_tag(:label,
2011 Jan 08
4
Help How to create DSL for conditional validations
Hi All,
I am new to Ruby and ROR
I were trying to create small DSL for conditional validations
valid_with_cond :bypass_validation do
if self.addresses > 3
errors[:base] << "Can not have more than 3 addresses".
end
end
By this I wanted to create array of method and call them all in custom
validation method.
this above code I wanted to do
attr_accessor
2006 Jun 14
5
uninitialized constant error after scaffold on new Windows XP environment
I am attempting to get a working Rails programming environment setup working
under XP with MySQL, RadRails and Webrick. I have been using my PowerBook
but need to working on Windows environment too.
I have basic functions of Ruby and Rails going. I created a really simple
table and generated the scaffolding. The server starts just fine. I can
browse the database succesfully in RadRails. The issue