Forum: Ruby on Rails Tutorials "How to develop plugins?"

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.
Jamal S. (Guest)
on 2007-03-26 15:25
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 :)

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

Thanks for your help :D
Chris H. (Guest)
on 2007-03-26 16:12
(Received via mailing list)
good place to start for the basics

http://wiki.rubyonrails.com/rails/pages/HowTosPlugins
Jamal S. (Guest)
on 2007-03-26 16:56
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 ?
Chris H. (Guest)
on 2007-03-26 17:42
(Received via mailing list)
perhaps a rake task would be what you want then?
Jamal S. (Guest)
on 2007-03-26 18:12
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 :D that would be
cool

Thanks for your replies :D
ruby lang (Guest)
on 2007-03-26 19:19
(Received via mailing list)
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
Jamal S. (Guest)
on 2007-03-26 21:46
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?
ruby lang (Guest)
on 2007-03-26 22:08
(Received via mailing list)
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/r...

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
Jamal S. (Guest)
on 2007-03-27 02:09
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?
ruby lang (Guest)
on 2007-03-27 05:07
(Received via mailing list)
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.
Jamal S. (Guest)
on 2007-03-27 11:12
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 :)

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 :D

Hope someone can help me through this...
This topic is locked and can not be replied to.