similar to: Plugin - How to access object from instance method

Displaying 20 results from an estimated 3000 matches similar to: "Plugin - How to access object from instance method"

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 Sep 04
2
"include" versus "extend" - what's the difference
Hi, Just wondering when one would use "include" over "extend"? Both seem to bring in methods to the class no? The context is I''m just trying to understand why both are used with the acts_as_audited plugin: Full extract from plugin (used within here): ================================================== # Copyright (c) 2006 Brandon Keepers # # Permission is hereby
2011 Jul 11
2
Can't get this Rspec test to pass
Hello, I''m completely new to Rspec testing and I''m finding it very difficult to mock specific objects. In this test, I have a before block setup as such: [code] before do setup_controller_for_warden controller.session[:operation_id] = 1 @operator = Factory :operator sign_in :operator, @operator @persist_herd = Herd.new
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 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
2006 Apr 10
3
Simple act_as template
Hello ! I posted a simple template to show how to add ''act_as_whatever'' to ActiveRecord. I think this might be useful to others as there are some trickery ruby things in this file. Here is the template : http://textsnippets.com/posts/show/384 Gaspard Bucher -- Posted via http://www.ruby-forum.com/.
2006 May 11
1
acts_as_paranoid and nested scopes in Rails 1.1
I have a real problem with the acts_as_paranoid plugin. The find-scope nesting does not seem to work at all. The description: I made a copy of ''acts_as_paranoid'' in the plugin directory, renamed it to ''acts_as_very_new''(just nonsense plugin for testing), and just simplified the code: #-------------------------------------------------------------- module
2012 Jan 23
0
Problem loading modules through ActiveSupport on_load
Working with modules to group certain methods. Currently I have this set up and it works: **# app/models/a.rb** class A has_history end **# lib/history.rb** module History module Model def self.included(base) base.send :extend, ClassMethods end module ClassMethods def has_history(options = {}) send :include,
2006 May 11
0
acts_as_paranoid, aliasing and nested scopes in Rails 1.1
I have a real problem with the acts_as_paranoid plugin. The aliasing of find and so the nested scope does not seem to work at all, when combining it with similar plugins. The description: I made a copy of ''acts_as_paranoid'' in the plugin directory, renamed it to ''acts_as_very_new''(just a nonsense plugin for testing), and simplified the code (original code
2006 Mar 28
0
How to set session variable in plug-ins
I''m working on a plug-in which has to manipulate some session varibles Unfortunately I end up with "Symbol as array index" errors. Probably the error occurs in a point that I never think about but here''s an abstract plug-in which generates the same error. It fails in the line of assignment "session[:aaa_uid] = uid" with "Symbol as array index"
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
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__) +
2012 Jan 28
2
after_save in plugin
Dear list, I am trying to override an after_save callback declared in main app using plugin. The main model class is: class WorkHours < ActiveRecord::Base @after_save_call_back_called=0 after_save :after_save_call_back def after_save_call_back logger.debug "after save called" @after_save_call_back_called=1 end end And in my plugin (in the lib directory) : module
2006 Feb 01
4
exclude a column in save!
Hi all, I have a column that peeks its value from a sequence (postgres) some times. Other times, I set it to a certain value. This column has a default value of "nextval(''the_sequence'')"... When I want that this column peeks the value from the sequence, I do this: obj = Mymodel.new obj.some_column1 = blah obj.some_column2 = blah obj.some_column3 = blah obj.save! but
2005 Dec 30
1
metaprogramming in controller: accessing instance variables
Hi all, I''m trying to move a bunch of methods out of a controller into a library that I can include and call a class method to have it dynamically add a bunch of methods to the controller. The goal is to just add to each controller: include UIEnhancements::SubList sub_list ''Note'', ''incomplete'' and have the sub_list method create all the methods
2006 Jun 21
1
Plugin Panic! - no accessing a model''s class methods?
Hi plugin-authors. So this is a little bit of take two on this question, but why can''t I access a singleton on the model calling my plugin? The crux of the full plugin below is: #logger.info self.class.to_s new_copy = self.class.new( @copyable_attributes ) the logger spits out "Datatype", but I get an error from rails saying: undefined method `datatype'' for
2006 Mar 29
2
inserts now set unset columns to null
Hi, I upgraded to Ruby 1.8.4 and whatever the latest Rails is as of March 29 2006. I am using PostgreSQL 7.4. With the earlier version of rails, I had insert queries that looked like this: Topic Create (0.001189) INSERT INTO topics ("inlibrary", "irx_display_title", "irx_title", "title", "creation_stamp", "last_update_stamp",
2015 Jul 16
3
[LLVMdev] why LoopUnswitch pass does not constant fold conditional branch and merge blocks
Hi, I have a general question on LoopUnswtich pass. Consider the following IR snippet: define i32 @test(i1 %cond) { br label %loop_begin loop_begin: br i1 %cond, label %loop_body, label %loop_exit loop_body: br label %do_something do_something: call void @some_func() noreturn nounwind br label %loop_begin loop_exit: ret i32 0 } declare void @some_func() noreturn After running
2006 May 17
9
Render No Layout?
Hi guys, Am having a problem. I have this def in my index controller that works like this: def do_something $a = variable1 $b = variable2 $c = variable3 $d = ""<script language=\"Javascript\"> \n new Insertion.Bottom(''#{$c}'', ''#{$a} - #{$b}''); \n </script>" $trigger = "1" render(:partial =>
2006 Jun 18
2
Adding a instance method
Hi all, I''d like to add a instance method to class String. I should be fairly simple with class String; def newmethod; do_something ; end; end and it works perfectly if I test this independently with irb. However if I add this to my application.rb I''ll get an error like (undefined method `newmethod'' for "123456":String) What''s wrong with that?