Tutorials "How to develop plugins?"


#1

I have been searching the WHOLE internet for a guide “How to develop
plugin” for rails web application? but there was NONE???

I’m trying to do develop this kind of plugins, I hope someone out there
can point me on the right direction :slight_smile:

http://www.ruby-forum.com/topic/102607

Thanks for your help :smiley:


#2

good place to start for the basics

http://wiki.rubyonrails.com/rails/pages/HowTosPlugins


#3

Chris H. wrote:

good place to start for the basics

http://wiki.rubyonrails.com/rails/pages/HowTosPlugins

I have already been in there, nothing valuable to start with?

Did you take a look at the topic I made, I don’t know if this can be
called plugin ?


#4

perhaps a rake task would be what you want then?


#5

Chris H. wrote:

perhaps a rake task would be what you want then?

I’m unfamiliar with that but it sound cool:P

…after doing some googling I see that the rake task is something like:

desc “Configure Subversion for Rails”
task :configure_for_svn do
system “svn remove log/"
system “svn commit -m ‘removing all log files from subversion’”
system 'svn propset svn:ignore "
.log” log/’
system “svn update log/”
system “svn commit -m ‘Ignoring all files in /log/ ending in .log’”
end

In this case I will face some problem, to update the roube.rb file
without replacing it, to add some map.connect to it?

Can I store the files somewhere on the internet also :smiley: that would be
cool

Thanks for your replies :smiley:


#6

ruby lang wrote:

Then Rails::Generator::NamedBase has a method to do this. I found it
while

Hope this is useful.

Stephen B. IV

What does this code do exactly? and how do you run it?


#7

Then Rails::Generator::NamedBase has a method to do this. I found it
while
making a generator to generate generators. I have yet to use this fun
resource but here is the code.

m.route_resources(*resources)

#from the command.rb

    def route_resources(*resources)
      resource_list = resources.map { |r| r.to_sym.inspect }.join(', 

')
sentinel = ‘ActionController::Routing::Routes.draw do |map|’

      logger.route "map.resources #{resource_list}"
      unless options[:pretend]
        gsub_file 'config/routes.rb', 

/(#{Regexp.escape(sentinel)})/mi
do |match|
“#{match}\n map.resources #{resource_list}\n”
end
end
end
Hope this is useful.

Stephen B. IV


#8

I believe it creates the route.rb file with the resources that are
passed
in, and tries to add it to the current routes. This is a method from the
generator base class. When you create a generator its one of the methods
you
have access to. I did not notice before the gsub_file is another method.
I
am using a frozen version of rails, but the file I found these in are in
the
vender/railites/lib/rails_generator/command.rb I was under the
impression
that you wanted to update the routes file and I believe that this is
what
this code does.

As for using it. I have not. The only place I have seen this used is
here
http://canofcode.com/rails/repository/6069/trunk/railties/lib/rails_generator/generators/components/resource/resource_generator.rb

Looks like they just pass the name of the resource to it. You might have
to
tweak the out put to the routes file.

def gsub_file(relative_destination, regexp, *args, &block)
path = destination_path(relative_destination)
content = File.read(path).gsub(regexp, *args, &block)
File.open(path, ‘wb’) { |file| file.write(content) }
end

Stephen B. IV


#9

ruby lang wrote:

I believe it creates the route.rb file with the resources that are
passed
in, and tries to add it to the current routes. This is a method from the

Stephen B. IV

This seems so complicated, I really thought it should be much easier.

Does this mean I cannot reuse my previous code easily in RoR?


#10

On 3/26/07, Jamal S. removed_email_address@domain.invalid wrote:

Does this mean I cannot reuse my previous code easily in RoR?


Posted via http://www.ruby-forum.com/.

You can you reuse your code in RoR applications. Looking at the
http://www.ruby-forum.com/topic/102607 post you can make a plugin (which
I
have not) or a generator. For a generator you can make template of files
and
then run ruby script/generate that_thing_you_made with_some options_too

How complicated are your files? Do they need to dynamic? SVN externals
could
work too.


#11

ruby lang wrote:

On 3/26/07, Jamal S. removed_email_address@domain.invalid wrote:

Does this mean I cannot reuse my previous code easily in RoR?


Posted via http://www.ruby-forum.com/.

You can you reuse your code in RoR applications. Looking at the
http://www.ruby-forum.com/topic/102607 post you can make a plugin (which
I
have not) or a generator. For a generator you can make template of files
and
then run ruby script/generate that_thing_you_made with_some options_too

How complicated are your files? Do they need to dynamic? SVN externals
could
work too.

Thanks for your reply :slight_smile:

my files is simple…

app/models/user.rb
app/controllers/user.rb
app/controllers/application.rb (few methods here) but they can be inside
/lib/ if this would not make it complicated.
app/views/user/
and /config/route.rb (also few routing)
last /db/migrate/001_create_users.rb/ (for creating the table)

This should be my plugin or what ever it can be called :smiley:

Hope someone can help me through this…