Forum: Ruby on Rails creating a rails plugin

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.
C7da1c726f89b6b7c37e8a22c0e0382d?d=identicon&s=25 Amita Bhatkhande (amita0204)
on 2009-02-17 16:56
I am trying to develop a rails plugin. I am referring to instructions
on: http://guides.rubyonrails.org/creating_plugins.html
I am quite confused about where should I start.

1. If I need to add MVC to my plugin, then do I need to follow
http://guides.rubyonrails.org/creating_ … test_setup ? I am not really
extending core classes or adding new method to ActiveRecord.

2. How do I install the generated plugin using 'script/plugin install
location'? Should one copy the entire 'vendor/plugins/yaffle' directory
somewhere and give its path in the install location field?

--
Amita.
C7da1c726f89b6b7c37e8a22c0e0382d?d=identicon&s=25 Amita Bhatkhande (amita0204)
on 2009-02-17 16:58
Corrected URL link.

Amita Bhatkhande wrote:
> I am trying to develop a rails plugin. I am referring to instructions
> on: http://guides.rubyonrails.org/creating_plugins.html
> I am quite confused about where should I start.
>
> 1. If I need to add MVC to my plugin, then do I need to follow
> http://guides.rubyonrails.org/creating_ … test_setup ? I am not really
> extending core classes or adding new method to ActiveRecord.
>
> 2. How do I install the generated plugin using 'script/plugin install
> location'? Should one copy the entire 'vendor/plugins/yaffle' directory
> somewhere and give its path in the install location field?
>
> --
> Amita.

1. If I need to add MVC to my plugin, then do I need to follow
http://guides.rubyonrails.org/creating_plugins.html#_tests . test_setup
? I am not really extending core classes or adding new method to
ActiveRecord.

Corrected URL link.
A91bd6cef23eb3516245a092e196c4da?d=identicon&s=25 Maurício Linhares (mauricio)
on 2009-02-17 18:02
(Received via mailing list)
What do you mean by "i need to add MVC"?

What do you want your plugin to do?

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)



On Tue, Feb 17, 2009 at 12:56 PM, Amita Bhatkhande
C7da1c726f89b6b7c37e8a22c0e0382d?d=identicon&s=25 Amita Bhatkhande (amita0204)
on 2009-02-17 18:18
I have a working rails application. I would like to move the user
management part of the application into a plugin structure (make a
plugin for user management). So that I don't have to repeat the same for
another application with similar user management requirements.

So I am trying to make a plugin from the Model, View, and Controller of
this user management part of my application.

-
Amita.


Maurício Linhares wrote:
> What do you mean by "i need to add MVC"?
>
> What do you want your plugin to do?
>
> -
> Maur�cio Linhares
> http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
> (en)
>
>
>
> On Tue, Feb 17, 2009 at 12:56 PM, Amita Bhatkhande
A91bd6cef23eb3516245a092e196c4da?d=identicon&s=25 Maurício Linhares (mauricio)
on 2009-02-20 21:19
(Received via mailing list)
Hi Amita,

Not really sure if you still need it, but a good source of ideas is
the Translate plugin (
http://github.com/newsdesk/translate/tree/master ). They do exactly
what you're looking for and it works like a charm, i bet you can get
some ideas to get your code working.

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)



On Tue, Feb 17, 2009 at 2:18 PM, Amita Bhatkhande
C7da1c726f89b6b7c37e8a22c0e0382d?d=identicon&s=25 Amita Bhatkhande (amita0204)
on 2009-02-22 02:39
Thanks Maurício for sharing the resources..

I have already made some progress, but now stuck with another problem
related to REST and Ajax.updater (to automatically populate timezones
depending on U.S.A. state selected).

-
Amita

 Linhares wrote:
> Hi Amita,
>
> Not really sure if you still need it, but a good source of ideas is
> the Translate plugin (
> http://github.com/newsdesk/translate/tree/master ). They do exactly
> what you're looking for and it works like a charm, i bet you can get
> some ideas to get your code working.
>
> -
> Maurício Linhares
> http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
> (en)
>
>
>
> On Tue, Feb 17, 2009 at 2:18 PM, Amita Bhatkhande
A91bd6cef23eb3516245a092e196c4da?d=identicon&s=25 Maurício Linhares (mauricio)
on 2009-02-22 04:40
(Received via mailing list)
And what`s the problem?

Doing it is quite straightforward after you have the list of timezones
based on states :)

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)



On Sat, Feb 21, 2009 at 10:39 PM, Amita Bhatkhande
C7da1c726f89b6b7c37e8a22c0e0382d?d=identicon&s=25 Amita Bhatkhande (amita0204)
on 2009-02-23 00:00
My current application is for picture albums. These picture albums are
oraganized/created as per the location. I am just doing it for my
learning purpose. I am trying to make a user management plugin for it.
The basic application worked with no plugin is working fine.


Initially I had models like this:

class Album < ActiveRecord::Base
  validates_presence_of :title, :state_id
  validates_uniqueness_of :title
  has_many :photos
  belongs_to :state
end

class Photo < ActiveRecord::Base
  belongs_to :album
end

class State < ActiveRecord::Base
  validates_presence_of :name, :country_id
  has_many :albums
  belongs_to :country
  has_many :users
end

class Country < ActiveRecord::Base
  validates_presence_of :name
  validates_uniqueness_of :name
  has_many :states
end

class User < ActiveRecord::Base
  validates_presence_of :username, :password_hash, :password_salt,
:role_id
  validates_uniqueness_of :username
  belongs_to :state
  belongs_to :role
  before_destroy :dont_delete_admin
end

class Role < ActiveRecord::Base
  validates_presence_of :name
  validates_uniqueness_of :name
  before_destroy :dont_destroy_admin
  has_many :users
end


Now for making a plugin I placed my user, role, state, country model in
the vendor/plugins/user_test/lib/app/models directory. However, placing
entire model class in the plugins/models directory may not work. Since
tomorrow the application could be for songs related to particular
location. So for the state model placing this line
plugins/models/state.rb- 'has_many albums' does not make any sense.

So can I place part of my model definition in the plugin and then one
can modify the albums and state models. This is not a good idea
though... Basically I don't know how should I proceed given this
situation. Any help?

-
Amita.


Maurício Linhares wrote:
> And what`s the problem?
>
> Doing it is quite straightforward after you have the list of timezones
> based on states :)
>
> -
> Maur�cio Linhares
> http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
> (en)
>
>
>
> On Sat, Feb 21, 2009 at 10:39 PM, Amita Bhatkhande
A91bd6cef23eb3516245a092e196c4da?d=identicon&s=25 Maurício Linhares (mauricio)
on 2009-02-23 12:48
(Received via mailing list)
What you`re looking for is a way to configure your plugin, the
simplest way to do it is just let the user reopen your classes and
change what is need in a initialization file. You could also create a
configuration file and have your plugin to load it and configure the
pieces that are "configurable", like the model that`s going to be used
(in your case, the photos our albuns).

Also, model plugins are usually small and very specific in what they
do, your plugin seems to do a  lot and this isn't really common when
dealing with plugins. Some plugins, like restful_auth, don't even use
models, but contain modules that are included in your models, this is
better `cos it's easier for someone using your plugin to override your
behaviour.

You should definitely take a look at the Rails Plugins patterns PDF ->
http://peepcode.com/products/rails-2-plugin-patterns

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)



On Sun, Feb 22, 2009 at 8:00 PM, Amita Bhatkhande
C7da1c726f89b6b7c37e8a22c0e0382d?d=identicon&s=25 Amita Bhatkhande (amita0204)
on 2009-02-25 05:21
Thanks for the link.. I am going through the guide.
However, I am still wondering how can I include associations (has_many
and belongs_to methods) in my plugin. Because I do not know what will be
the model/table name used by user to associate my plugin's model to..

e.g.: for one application it could be user- :has_many photos or for
another application- user :has_many songs .

Thanks,
Amita.


Maurício Linhares wrote:
> What you`re looking for is a way to configure your plugin, the
> simplest way to do it is just let the user reopen your classes and
> change what is need in a initialization file. You could also create a
> configuration file and have your plugin to load it and configure the
> pieces that are "configurable", like the model that`s going to be used
> (in your case, the photos our albuns).
>
> Also, model plugins are usually small and very specific in what they
> do, your plugin seems to do a  lot and this isn't really common when
> dealing with plugins. Some plugins, like restful_auth, don't even use
> models, but contain modules that are included in your models, this is
> better `cos it's easier for someone using your plugin to override your
> behaviour.
>
> You should definitely take a look at the Rails Plugins patterns PDF ->
> http://peepcode.com/products/rails-2-plugin-patterns
>
> -
> Maurício Linhares
> http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
> (en)
>
>
>
> On Sun, Feb 22, 2009 at 8:00 PM, Amita Bhatkhande
A91bd6cef23eb3516245a092e196c4da?d=identicon&s=25 Maurício Linhares (mauricio)
on 2009-02-25 16:21
(Received via mailing list)
Usually, plugins do it by using polymorphic associations, so they
don't need to know in advance the real class that's going to be
referenced.

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)



On Wed, Feb 25, 2009 at 1:21 AM, Amita Bhatkhande
0c31801aba0747b84974df56ade208f3?d=identicon&s=25 rob doan (Guest)
on 2009-03-02 00:24
(Received via mailing list)
I hope this book will help you create a plugin.

http://rapidshare.com/files/204193424/Addison-Wesl...
Best regards
Rob.
This topic is locked and can not be replied to.