Displaying 20 results from an estimated 2000 matches similar to: "include ClassMethods in plugins"
2005 Aug 10
1
using modules with models?
I''m trying to figure out how to use modules with my model classes.
I''m going to have good number of model classes that don''t map to the
database, and I''d like to put some of these in seperate modules. I''ve
been wrestling with this for 2 days and can''t figure out how to get it
to work. Rails seems to handle it fine for controllers, though.
I
2005 May 14
2
ActiveRecord::Associations::ClassMethods Documentation Issue
I''m curious, but isn''t this example in the documentation for
ActiveRecord::Associations::ClassMethods somewhat counter-intuitive? The SQL
DDL is correct for the way it''s used in the models. But isn''t it more
logical that an author would have many posts, rather than many authors
having one post?
From
2007 Nov 20
2
Plugin: create instance methods dynamically in ClassMethods?
Hi all
I have the following plugin code:
module IncenseCrud
def self.included(base_class)
base_class.extend(ClassMethods)
end
module ClassMethods
def performs_incense_crud
def index
list
return render(:action => ''list'')
end
end
end
end
In init.rb I have the following:
require File.dirname(__FILE__) +
2015 Oct 27
3
Add a mapping to a C++ lambda
Apologies for the noop question in advance (just getting started with
LLVM), and I'm not entirely sure if this is the right list to post to. is
it?
I have some lambda functions as member variables that I want to have my
LLVM language make calls to. I've added a mapping to them, but this doesn't
seem to enable LLVM to resolve the functions. I asked on stackoverflow but
the suggestion
2012 Nov 23
3
how to query yaml file with hiera function.
Hi guys,
i have a hiera.yaml config file like this:
---
:hierarchy:
- %{env}/%{tmp_module_name}
- %{env}/%{tmp_module_name}.common
:backends:
- yaml
:yaml:
:datadir: ''/etc/puppet/hieradata''
I also have a test/some_module.yaml file like this:
---
db:
root : pass
port : ''3306''
I am also using the hiera function
2006 Jun 22
1
acts_as_taggable gem problems
With acts_as_taggable 1.04...
1. how can I get a frequency of tags?
i.e. /tags/list I want to list of tags sorted and listed with
their frequency
tags_controller.rb:
def list
@tags = Tags.find_by_sql ''select name, count(*) as freq from tags
group by name order by freq desc''
End
tags/list.rb:
<ul>
<% @tags.each do |t| %>
<li><%= t.freq %>
2012 Oct 18
0
unexpected return (LocalJumpError) only when executing this code within autoloaded classes?
Posted on stackoverflow but no traction yet:
http://stackoverflow.com/questions/12942505/why-does-using-set-trace-func-work-in-some-places-but-cause-unexpected-return-l
The following is a generified part of the code in a gem I''m working on:
module SomeModule
class << self
attr_accessor :procedure
def log_events(*args)
args.flatten!
2008 Apr 01
1
plugin announcement: acts_as_fu
We''ve all seen the job listings. We know what they''re looking for.
Rockstars. Code Monkeys. Rails Ninjas.
And you''re left thinking, "But I''m just a programmer." Well, not
anymore. Today, you become a Rails Kung-Fu Master!
"Not me," you say. "I''ve already tried using all the acts_as_something
plugins and all the something_fu
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
2006 Jun 07
1
validates_presence_of in a mixed-in module?
Anyone got any idea of how to use built-in validation methods in a
mixed-in module.
What I''ve got at the moment is each class that needs ranking methods
includes [the module] Ranking. Then the module Ranking has a bunch of
instance methods and a submodule ClassMethods. The ClassMethods in this
are mixed in to the class with self.included. So far so good.
But I want the module to
2006 May 17
3
Help mixin in class methods
Starting to feel more confident and code is DRYing up nicely, but I''ve
hit a brick wall here and hoping someone can help me.
I''ve got a module, TrustRanking, which extends a number of model''s
instance methods, and I want to extend their class methods too, but I
can seem to work out how to do it.
Simply including the module from the class works a treat for the
2007 Jun 27
5
Filter Ordering in Edge Rails (Rev 7143)
Filter chaining appears to behave in differently than Rails 1.2.x. It
seems that I''m getting a lot of errors along the lines of:
ActionController::ActionControllerError: filter
#<ActionController::Filters::ClassMethods::BeforeFilterProxy:0x322f468
@filter=#<ActionController::Filters::ClassMethods::SymbolFilter:
0x322f4b8 @filter=:login_required>> was in the wrong place!
2006 Apr 18
4
Mixin variables
I''ve created an access control module that I''m including in several
different controllers. Everything works fine, but I want to allow each
controller to override the default login page with something like this:
set_login_pages :secure => ''my_login''
In my module, I''ve set up the set_login_pages method like this:
def self.included(base)
2009 Dec 27
5
Difficulties in understanding Rail-Plugins in depth
Hi,
i try to understand how plugins work in detail.
Often you see stuff like:
class Post < ActiveRecord::Base
acts_as_commentable
end
I wonder what''s happen all there.
What kind of language-feature is behind this call "acts_as_commentable" ?
In my opinion you need some kind of extend or include to extend the
functionality of a model. And exactly this is which i found
2006 Jun 03
1
Can I tell if the associated record is new in a belongs_to save?
In a belongs_to association, is there a way to tell if the associated object
was newly created?
Hopefully this will explain my question:
A Firm class declares
has_many<http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M000530>:clients
and a
client class declares
2007 Nov 27
1
Plugin - How to access object from instance method
Quick question: Given a basic plugin... how can I access an object that
I instantiated in the acts_as method from an instance method? Probably
some sort of accessor... but where?
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def acts_as_test
object = Object.new ## This object needs to be accessible from the
Instance Methods
end
include
2009 Sep 11
0
Need help with extending a plugin
hey folks
I''ve installed the plugin acts_as_taggable_on_steroids (henceforth
aatos), and i already have some tagging functionality set up, using the
same approach (ie a Tag and a Tagging class with associated tables) as
aatos.
So, i want my existing Tag and Taggings methods, plus some other methods
i have in a module which i include with the taggable classes (ie the
ones that would call
2006 Jun 26
5
How can I dynamiclly generate models?
I am trying to write a plugin, ''acts_as_commentable'', for my models -
Image, Book, Music and so on, I do not want to use polymorphic
association, so very model should have its own comment class.
Here is my code
acts_as_commentable.rb
module Commentable
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def
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
2006 May 26
3
validate a form NOT connected to a model
Is there any way to validate a form that isn''t connected to a model. I have
a form that connects to a controller action and I want to validate the
inputs on the form like I would with the validates_ATTRIBUTE_of property on
a model. Is there any way to do this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: