Uno scrittoio digitale …

1 luglio 2016

Cecorator pattern with Modules

Archiviato in: rails — admin @ 08:26

class Tattoo
  def price
    300
  end
end

module ColourTattoo
  def price
    super + 150
  end
end

module BigTattoo
  def price
    super + 200
  end
end

tattoo = Tattoo.new
tattoo.extend(ColourTattoo)
tattoo.extend(BigTattoo)

9 giugno 2016

can I access session variable in model

Archiviato in: rails — Tag: — admin @ 10:13

Yes you could access the session variable in model. Paste the below
code in application.rb
————–

  around_filter :you_dont_have_bloody_clue

  protected

  def you_dont_have_bloody_clue
    klasses = [ActiveRecord::Base, ActiveRecord::Base.class]
    methods = ["session", "cookies", "params", "request"]

    methods.each do |shenanigan|
      oops = instance_variable_get(:"@_#{shenanigan}")

      klasses.each do |klass|
        klass.send(:define_method, shenanigan, proc { oops })
      end
    end

    yield

    methods.each do |shenanigan|
      klasses.each do |klass|
        klass.send :remove_method, shenanigan
      end
    end

  end

————–

Now continue using the session variable in model. It works for me.
Thanks,
Sadeesh.

3 giugno 2016

Advanced ROR

Archiviato in: rails, sapere è potere, web — Tag:, — admin @ 16:47

https://gist.github.com/mnutt/566725
https://signalvnoise.com/posts/3091-pssst-your-rails-application-has-a-secret-to-tell-you
http://rubyjunky.com/cleaning-up-rails-4-production-logging.html
http://www.spacevatican.org/2011/4/28/adding-to-rails-log-file-performance-breakdown/

ROR Api
Notifications
Concern
Instrumentation
LogSubscriber

8 gennaio 2016

ruby-debug gem

Archiviato in: rails — Tag:, — admin @ 19:00

guide

4 gennaio 2016

Attacking ruby on rails

Archiviato in: rails — Tag: — admin @ 19:10

http://www.phrack.org/papers/attacking_ruby_on_rails.html

6 novembre 2014

Ruby on Rails application server solution

Archiviato in: code, rails — Tag:, — admin @ 17:24

Giusto qualche link utile per capire le alternative:

phusion-passenger-for-dummies
ruby-on-rails-server-options
rack

26 settembre 2014

The Ruby ‘Struct’ Class

Archiviato in: rails — admin @ 16:16

Riporto la definizione scritta nelle Ruby documentation:

Struct is “a convenient way to bundle a number of attributes together, using accessor methods, without having to write an explicit class.”

Esempio:

Person = Struct.new(:name, :age, :gender) do
  def greet_world
    "Hello world, my name is #{name}."
  end
  def ask_question
    "What is your favorite programming language?"
  end
end

stephanie = Person.new("Stephanie", "26", "female")

stephanie.name          # => "Stephanie"
stephanie.age           # => "26"
stephanie.gender        # => "female"

stephanie.greet_world   # => "Hello world, my name is Stephanie."
stephanie.ask_question  # => "What is your favorite programming language?"

23 settembre 2014

42

Archiviato in: rails, sapere è potere — admin @ 12:49

Ho scoperto che in un modulo di Rails che non fà altro che aggiungere metodi alla class Array è esplicitato il metodo forty_two:

module ActiveSupport #:nodoc:
  module CoreExtensions #:nodoc:
    module Array #:nodoc:
      # Makes it easier to access parts of an array.
      module Access
        # Returns the tail of the array from +position+.
        #
        #   %w( a b c d ).from(0)  # => %w( a b c d )
        #   %w( a b c d ).from(2)  # => %w( c d )
        #   %w( a b c d ).from(10) # => nil
        #   %w().from(0)           # => nil
        def from(position)
          self[position..-1]
        end

        # Returns the beginning of the array up to +position+.
        #
        #   %w( a b c d ).to(0)  # => %w( a )
        #   %w( a b c d ).to(2)  # => %w( a b c )
        #   %w( a b c d ).to(10) # => %w( a b c d )
        #   %w().to(0)           # => %w()
        def to(position)
          self[0..position]
        end

        # Equal to self[1].
        def second
          self[1]
        end

        # Equal to self[2].
        def third
          self[2]
        end

        # Equal to self[3].
        def fourth
          self[3]
        end

        # Equal to self[4].
        def fifth
          self[4]
        end

        # Equal to self[41]. Also known as accessing "the reddit".
        def forty_two
          self[41]
        end
      end
    end
  end
end

da questo ho poi scoperto altri riferimenti a Douglas Adams:
http://www.quora.com/Why-is-Array-forty_two-called-the-reddit-in-Ruby-on-Rails
http://www.reddit.com/r/its42
http://www.reddit.com/r/fortytwo/

Mitico rails.

30 agosto 2014

RoR

Archiviato in: rails — admin @ 14:37

ror

Funziona con WordPress