Kristian Mandrup
2010-May-12 14:03 UTC
Trouble developing Rails plugins/gems with generators
Hi, I''ve been trying to develop a Rails gem/plugin with generators for Rails 3. I first had a separate gem project with a gem statement in my Gemfile with a :path option to point at it. But then I had to run $ rake install on each change in my gem to have Rails pick up on it. I have now instead put my generators inside RAILS_ROOT/lib so they are easier to test/develop. lib/generators - ability ability_generator.rb - clear - config When I run $ rails g ... AuthAssist: auth_assist:ability auth_assist:clear auth_assist:config $ rails g auth_assist:ability Could not find generator auth_assist:ability. What am I doing wrong here? Must the generators be in a gem/plugin to be picked up by Rails? What is the best/easiest approach for developing plugins/generators with Rails 3? Thanks! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Anuj Dutta
2010-May-12 14:12 UTC
Re: Trouble developing Rails plugins/gems with generators
On 12 May 2010 19:33, Kristian Mandrup <kmandrup@gmail.com> wrote:> Hi, > > I''ve been trying to develop a Rails gem/plugin with generators for > Rails 3. I first had a separate gem project with a gem statement in my > Gemfile with a :path option to point at it. But then I had to run $ > rake install on each change in my gem to have Rails pick up on it. I > have now instead put my generators inside RAILS_ROOT/lib so they are > easier to test/develop. > > lib/generators > - ability > ability_generator.rb > - clear > - config > > When I run $ rails g > ... > AuthAssist: > auth_assist:ability > auth_assist:clear > auth_assist:config > > $ rails g auth_assist:ability > Could not find generator auth_assist:ability. > > What am I doing wrong here? Must the generators be in a gem/plugin to > be picked up by Rails? > What is the best/easiest approach for developing plugins/generators > with Rails 3? > > Thanks! > >This might help... http://github.com/indirect/rails3-generators I have not really looked into generators recently but I am guessing not much has changed. Anuj> -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com<rubyonrails-core%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > >-- Anuj DUTTA -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Kristian Mandrup
2010-May-12 14:25 UTC
Re: Trouble developing Rails plugins/gems with generators
I worked it out myself. It had to do with the fact that the generators for some reason require the namespace to match a containing folder, much like the Java package mechanism. lib/generators - auth_asisst - ability ability_generator.rb # ability_generator.rb module AuthAssist module Generators class AbilityGenerator < Rails::Generators::Base ... A bit akward IMO, that a generator can be picked up as available but then can''t be found when attempting to run it. Would be nice with a better error message such as "can''t find x:y in generators/x/y_generator.rb as expected." -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Anuj Dutta
2010-May-12 14:27 UTC
Re: Re: Trouble developing Rails plugins/gems with generators
On 12 May 2010 19:55, Kristian Mandrup <kmandrup@gmail.com> wrote:> I worked it out myself. It had to do with the fact that the generators > for some reason require the namespace to match a containing folder, > much like the Java package mechanism. > > lib/generators > - auth_asisst > - ability > ability_generator.rb > > # ability_generator.rb > module AuthAssist > module Generators > class AbilityGenerator < Rails::Generators::Base > ... > > A bit akward IMO, that a generator can be picked up as available but > then can''t be found when attempting to run it. > Would be nice with a better error message such as "can''t find x:y in > generators/x/y_generator.rb as expected." > >Yeah, I have felt the need for a proper error message otherwise you can''t really tell what is going on. I will add a Lighthouse ticket for the same. Anuj --> You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com<rubyonrails-core%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > >-- Anuj DUTTA -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Kristian Mandrup
2010-May-12 15:19 UTC
Re: Trouble developing Rails plugins/gems with generators
On another note: I would like to have available the methods used in Rails 3 templates. I see many generators including Rails::Generators::Migration and using the method migration_template to create a new migration. What I would like is for my generator to create the options for running a basic migration command, say: $ rails g migration add_user_name_to_user user_name:string But to be run from inside my migration. I tried the following migration ''add_user_name_to_user user_name:string'' But the migration method is not available by default and I can''t seem to find it anywhere... any idea how to do this? I could hack it using "run" which works, but produces: run rails g migration add_admin_field_to_user admin:boolean from "." Which just doesn''t feel right ;) Thanks! On May 12, 10:27 am, Anuj Dutta <dutta.a...@googlemail.com> wrote:> On 12 May 2010 19:55, Kristian Mandrup <kmand...@gmail.com> wrote: > > > > > I worked it out myself. It had to do with the fact that the generators > > for some reason require the namespace to match a containing folder, > > much like the Java package mechanism. > > > lib/generators > > - auth_asisst > > - ability > > ability_generator.rb > > > # ability_generator.rb > > module AuthAssist > > module Generators > > class AbilityGenerator < Rails::Generators::Base > > ... > > > A bit akward IMO, that a generator can be picked up as available but > > then can''t be found when attempting to run it. > > Would be nice with a better error message such as "can''t find x:y in > > generators/x/y_generator.rb as expected." > > Yeah, I have felt the need for a proper error message otherwise you can''t > really tell what is going on. I will add a Lighthouse ticket for the same. > > Anuj > > -- > > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Core" group. > > To post to this group, send email to rubyonrails-core@googlegroups.com. > > To unsubscribe from this group, send email to > > rubyonrails-core+unsubscribe@googlegroups.com<rubyonrails-core%2Bunsubscribe@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-core?hl=en. > > -- > Anuj DUTTA > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-core?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Anuj Dutta
2010-May-12 15:20 UTC
Re: Re: Trouble developing Rails plugins/gems with generators
On 12 May 2010 20:49, Kristian Mandrup <kmandrup@gmail.com> wrote:> On another note: > > I would like to have available the methods used in Rails 3 templates. > I see many generators including Rails::Generators::Migration and using > the method migration_template to create a new migration. > What I would like is for my generator to create the options for > running a basic migration command, say: > $ rails g migration add_user_name_to_user user_name:string > > But to be run from inside my migration. I tried the following > > migration ''add_user_name_to_user user_name:string'' > > But the migration method is not available by default and I can''t seem > to find it anywhere... any idea how to do this? > I could hack it using "run" which works, but produces: > > run rails g migration add_admin_field_to_user admin:boolean from "." > > Which just doesn''t feel right ;) > > Thanks! > > >Just have a look at rails3-generators in github. It has got generators for datamapper, haml and so on. I am sure you can find clues there.> > On May 12, 10:27 am, Anuj Dutta <dutta.a...@googlemail.com> wrote: > > On 12 May 2010 19:55, Kristian Mandrup <kmand...@gmail.com> wrote: > > > > > > > > > I worked it out myself. It had to do with the fact that the generators > > > for some reason require the namespace to match a containing folder, > > > much like the Java package mechanism. > > > > > lib/generators > > > - auth_asisst > > > - ability > > > ability_generator.rb > > > > > # ability_generator.rb > > > module AuthAssist > > > module Generators > > > class AbilityGenerator < Rails::Generators::Base > > > ... > > > > > A bit akward IMO, that a generator can be picked up as available but > > > then can''t be found when attempting to run it. > > > Would be nice with a better error message such as "can''t find x:y in > > > generators/x/y_generator.rb as expected." > > > > Yeah, I have felt the need for a proper error message otherwise you can''t > > really tell what is going on. I will add a Lighthouse ticket for the > same. > > > > Anuj > > > > -- > > > > > You received this message because you are subscribed to the Google > Groups > > > "Ruby on Rails: Core" group. > > > To post to this group, send email to rubyonrails-core@googlegroups.com > . > > > To unsubscribe from this group, send email to > > > rubyonrails-core+unsubscribe@googlegroups.com<rubyonrails-core%2Bunsubscribe@googlegroups.com> > <rubyonrails-core%2Bunsubscribe@googlegroups.com<rubyonrails-core%252Bunsubscribe@googlegroups.com> > > > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-core?hl=en. > > > > -- > > Anuj DUTTA > > > > -- > > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > > To post to this group, send email to rubyonrails-core@googlegroups.com. > > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com<rubyonrails-core%2Bunsubscribe@googlegroups.com> > . > > For more options, visit this group athttp:// > groups.google.com/group/rubyonrails-core?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com<rubyonrails-core%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > >-- Anuj DUTTA -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Kristian Mandrup
2010-May-12 15:28 UTC
Re: Trouble developing Rails plugins/gems with generators
On a further note. I can''t seem to get any .rb files in RAILS_ROOT/lib to load when I start my rails server. Say I have a file # lib/auth_assistant.rb puts "Hello from AuthAssist" -- In the old days of Rails 2.3+ you would put a require statement in application.rb, but I think in Rails 3 all files in lib should be loaded by default!? How do I configure my lib files to be loaded in Rails 3? -- BTW: Thanks for creating the ticket :) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Anuj Dutta
2010-May-12 15:37 UTC
Re: Re: Trouble developing Rails plugins/gems with generators
On 12 May 2010 20:58, Kristian Mandrup <kmandrup@gmail.com> wrote:> On a further note. I can''t seem to get any .rb files in RAILS_ROOT/lib > to load when I start my rails server. > > Say I have a file > > # lib/auth_assistant.rb > puts "Hello from AuthAssist" > > -- > In the old days of Rails 2.3+ you would put a require statement in > application.rb, but I think in Rails 3 all files in lib should be > loaded by default!? > How do I configure my lib files to be loaded in Rails 3? > >I think you still need to require it in the application.rb file. I might be wrong as I have not been following the Rails-core development as much so don''t take my word for it. Anuj> -- > BTW: Thanks for creating the ticket :) > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com<rubyonrails-core%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > >-- Anuj DUTTA -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Kristian Mandrup
2010-May-13 19:15 UTC
Re: Trouble developing Rails plugins/gems with generators
It turned out I had to include the require statement in an initializer. Putting it in the application.rb didn''t work (not found error). I has to due with the load order I''m sure. Thanks for the help :)> > I think you still need to require it in the application.rb file. I might be > wrong as I have not been following the Rails-core development as much so > don''t take my word for it. > > Anuj >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Maybe Matching Threads
- Re: Exclude ActiveRecord in Rails3
- [threadsafe] Arel ToSql visitor is not threadsafe
- Rails plugins new official maintainers
- A "strict Arel" mode for ActiveRecord to prevent SQL injection vulnerabilities
- rails timezone difference in console and production application