Forum: Ruby on Rails using a plugin to modify Rails core?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 petermichaux (Guest)
on 2005-11-22 03:33
(Received via mailing list)
Hi,

I've been trying to learn about plugins by reading plugin source files
where
I can find them. I feel like the fog is clearing a little. Is it true
that a
plugin can be used to modify any part of the Rails core? If so, how can
I do
it? For example, say I want to create a plugin in
vendor/plugin/new_error
parts of ActiveRecord's Errors class.

Trimmed down from ActiveRecord it has this:

module ActiveRecord
class Errors
@@default_error_messages = {
:inclusion => "is not included in the list",
:exclusion => "is reserved",
:invalid => "is invalid"
}

def add_to_base(msg)
add(:base, msg)
end
end
end

and say I want to change it to this (I know, silly example):

module ActiveRecord
class Errors
@@default_error_messages = {
:inclusion => "is not included in the list, idiot",
:exclusion => "is reserved, ignoramus"
}

def add_to_base(msg)
foo = msg
add(:base, foo)
end
end
end

Would I need to have a vendor/plugin/new_error/init.rb file? What would
it
say?

Would vendor/plugin/new_error/lib/new_error.rb simply be what I want
above?

Thanks,
Peter
D6c13e82448f753fde1a51d79e59d92c?d=identicon&s=25 steve (Guest)
on 2005-11-22 07:14
(Received via mailing list)
hey everyone,
i read this article:
http://www.bitslapped.nl/articles/2005/06/05/rails...
but am still unable to get RoR working on win2k3/iis6.  i can confirm
that my app is working with WEBrick, but whenever i try to access it
with IIS, i get a 404 error.  i am pretty sure i have everything
configured correctly.
anyone have any tips to get this running?
thanks a lot!
steve
05d703f649ef1d07e78d7b479fb4c4ac?d=identicon&s=25 james.adam (Guest)
on 2005-11-22 10:59
(Received via mailing list)
In your init.rb file, you should require your new_error.rb file, and
that should be all you need. I.e.

vendor/plugins/new_error/init.rb:

  require 'new_error'  # note no 'lib/' here

vendor/plugins/new_error/lib/new_error.rb

  module ActiveRecord
    class Errors
      @@default_error_messages = {
        :inclusion => "is not included in the list, idiot",
        :exclusion => "is reserved, ignoramus"
        }

       def add_to_base(msg)
          foo = msg
          add(:base, foo)
      end
    end
  end


... and that should do the trick. Plugin code is (almost) the last
thing to load, so you can quite easily use it to hack about with Rails
internals (as I do to a small degree with the Engines plugin).

Hope this helps

- James
Cb610750ee94ca103aef4b2dc7b1b768?d=identicon&s=25 nicholas.stuart (Guest)
on 2005-11-22 14:57
(Received via mailing list)
Quick tip, delete all the log files in your app and restart IIS (not
just the site your app is using, the whole thing). Do you get log
files generated again? If so you're headed in the right direction. You
should have the environmnet log, and a couple fast-cgi logs generated.

Let us know if you get these or not and we can go from there.  :)

-Nick
D6c13e82448f753fde1a51d79e59d92c?d=identicon&s=25 steve (Guest)
on 2005-11-22 15:57
(Received via mailing list)
ok, did that.  now i'm getting "Server Error, unable to connect to
fastcgi server."
and no logs have been created in the log dir.
thanks for the tip...i guess i messed something up along the way while
configuring fastCGI?
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 petermichaux (Guest)
on 2005-11-23 02:26
(Received via mailing list)
I'm having troubles getting this to work. I have the following files and
reboot WEBrick but I do not see my redefined error messages. Any ideas?

Thanks,
Peter


= vendor/plugins/new_error/init.rb: =

require 'new_error'  # note no 'lib/' or '.rb' here

= vendor/plugins/new_error/lib/new_error.rb =

module ActiveRecord
  class Errors
    @@default_error_messages = {
      :inclusion => "pm is not included in the list",
      :exclusion => "pm is reserved",
      :invalid => "pm is invalid",
      :confirmation => "pm doesn't match confirmation",
      :accepted  => "pm must be accepted",
      :empty => "pm can't be empty",
      :blank => "pm can't be blank",
      :too_long => "pm is too long (max is %d characters)",
      :too_short => "pm is too short (min is %d characters)",
      :wrong_length => "pm is the wrong length (should be %d
characters)",
      :taken => "pm has already been taken",
      :not_a_number => "pm is not a number"
    }
  end
end
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 petermichaux (Guest)
on 2005-11-23 02:34
(Received via mailing list)
Do I have to make a reference to the plugin somewhere in my app to make
sure
that the plugin loads? I thought plugins were supposed to be auto
loading.

(If I put the vendor/plugins/new_error/lib/new_error.rb code in
application_controller.rb then I do see the new error messages. So the
plugin is not loading.)

Thanks,
Peter
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 petermichaux (Guest)
on 2005-11-23 03:10
(Received via mailing list)
It works just fine. Even though I am using Rails 14.3 the project was
generated with a Rails version less than 0.14 so the plugins didn't
work. I
didn't know the Rails version generating the app mattered. I genrated a
new
app and tried again and everything worked as expected.

-Peter
Cb610750ee94ca103aef4b2dc7b1b768?d=identicon&s=25 nicholas.stuart (Guest)
on 2005-11-23 13:52
(Received via mailing list)
You can also updgrade existing apps. From your current apps directory
just
run `rails .` and it will go through and update stuff. Becareful with
this
though, as it will override most of your config files.
This topic is locked and can not be replied to.