alias-method

undefined method `render' for class `ActionView::Base'

随声附和 提交于 2020-01-15 03:57:06
问题 When I start the application crashes following error /home/stereodenis/.rvm/gems/ruby-1.9.3-p194@nyanya/gems/haml-3.1.6/lib/haml/helpers/action_view_mods.rb:15:in `alias_method': undefined method `render' for class `ActionView::Base' (NameError) What maybe wrong? full trace https://gist.github.com/5e3244d488068c9d0ba7 回答1: If you are using a render inside a helper you have to include the functionality! include AbstractController::Rendering Hope it helps 来源: https://stackoverflow.com/questions

When should I use an Alias Method? - Ruby

≡放荡痞女 提交于 2019-12-24 13:49:50
问题 I've looked through and haven't seen an answer to: What would you use an alias method? class Vampire attr_reader :name, :thirsty alias_method :thirsty?, :thirsty end Is the only reason I would use one is to be able to use a question mark with whatever method I define? I believe you can't use question marks with instance variables. 回答1: I think this is from an earlier question I responded to, where I proposed using alias_method , so I have a little bit of extra context into this to explain it

alias_method and class_methods don't mix?

◇◆丶佛笑我妖孽 提交于 2019-12-20 12:10:24
问题 I've been trying to tinker with a global Cache module, but I can't figure out why this isn't working. Does anyone have any suggestions? This is the error: NameError: undefined method `get' for module `Cache' from (irb):21:in `alias_method' ... generated by this code: module Cache def self.get puts "original" end end module Cache def self.get_modified puts "New get" end end def peek_a_boo Cache.module_eval do # make :get_not_modified alias_method :get_not_modified, :get alias_method :get, :get

Why alias_method fails in Rails model

不问归期 提交于 2019-12-18 01:52:21
问题 class Country < ActiveRecord::Base #alias_method :name, :langEN # here fails #alias_method :name=, :langEN= #attr_accessible :name def name; langEN end # here works end In first call alias_method fails with: NameError: undefined method `langEN' for class `Country' I mean it fails when I do for example Country.first . But in console I can call Country.first.langEN successfully, and see that second call also works. What am I missing? 回答1: ActiveRecord uses method_missing (AFAIK via ActiveModel:

alias_method and class_methods don't mix?

南楼画角 提交于 2019-12-03 02:17:17
I've been trying to tinker with a global Cache module, but I can't figure out why this isn't working. Does anyone have any suggestions? This is the error: NameError: undefined method `get' for module `Cache' from (irb):21:in `alias_method' ... generated by this code: module Cache def self.get puts "original" end end module Cache def self.get_modified puts "New get" end end def peek_a_boo Cache.module_eval do # make :get_not_modified alias_method :get_not_modified, :get alias_method :get, :get_modified end Cache.get Cache.module_eval do alias_method :get, :get_not_modified end end # test first

Unexpected value of __callee__ when including a module – is this a Ruby bug?

白昼怎懂夜的黑 提交于 2019-12-01 03:11:57
When invoked via a method created by alias_method , __callee__ ignores the name of the old method (here xxx ) and returns the name of the new method, as below: class Foo def xxx() __callee__ end alias_method :foo, :xxx end Foo.new.foo # => :foo This behavior holds even when xxx is inherited from a superclass: class Sup def xxx() __callee__ end end class Bar < Sup alias_method :bar, :xxx end Bar.new.bar # => :bar Given both of the above, I would expect that the same behavior would hold when xxx is included via a module. However, that is not the case: module Mod def xxx() __callee__ end end

Unexpected value of __callee__ when including a module – is this a Ruby bug?

不打扰是莪最后的温柔 提交于 2019-11-30 22:31:05
问题 When invoked via a method created by alias_method , __callee__ ignores the name of the old method (here xxx ) and returns the name of the new method, as below: class Foo def xxx() __callee__ end alias_method :foo, :xxx end Foo.new.foo # => :foo This behavior holds even when xxx is inherited from a superclass: class Sup def xxx() __callee__ end end class Bar < Sup alias_method :bar, :xxx end Bar.new.bar # => :bar Given both of the above, I would expect that the same behavior would hold when

Why alias_method fails in Rails model

梦想的初衷 提交于 2019-11-28 22:54:52
class Country < ActiveRecord::Base #alias_method :name, :langEN # here fails #alias_method :name=, :langEN= #attr_accessible :name def name; langEN end # here works end In first call alias_method fails with: NameError: undefined method `langEN' for class `Country' I mean it fails when I do for example Country.first . But in console I can call Country.first.langEN successfully, and see that second call also works. What am I missing? ActiveRecord uses method_missing (AFAIK via ActiveModel::AttributeMethods#method_missing ) to create attribute accessor and mutator methods the first time they're