ryanb / nifty-generators Goto Github PK
View Code? Open in Web Editor NEWA collection of useful Rails generator scripts.
License: MIT License
A collection of useful Rails generator scripts.
License: MIT License
rails g nifty:scaffold admin::city name:string
After it, one can see this line in routes.rb:
resources :"admin/cities"
And this line broke any other scaffold: /usr/lib/ruby/gems/svn/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/route_set.rb:146:in `module_eval': /usr/lib/ruby/gems/svn/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/route_set.rb:147: syntax error, unexpected '/', expecting ';' or '\n' (SyntaxError) ... def hash_for_admin/cities_url(options = nil) ... ... ^ /usr/lib/ruby/gems/svn/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/route_set.rb:149: syntax error, unexpected keyword_end, expecting $end end
ruby 1.9.3dev (2010-05-08 trunk 27674) [x86_64-linux]
Rails 3 beta 4
Rather than simply redirecting to the login_url, store the original destination URL in the session and redirect there upon successful login.
It'd be nice it the generated views could be readily modified to use Rail's build in i18n system, so that all the phrases would be found in an en.yml file which could easily be translated into other languages. This feature could of course be a non-default option.
I tries to install it locally after downloading it from gemcutter:
[code]
C:\Documents and Settings\MACHINE_DEV3\My Documents\libs\gems\rails3.0>gem install nifty-generators -l
Successfully installed nifty-generators-0.4.1
1 gem installed
Installing ri documentation for nifty-generators-0.4.1...
ERROR: While executing gem ... (Errno::EINVAL)
Invalid argument - ./</cdesc-<.ri
C:\Documents and Settings\MACHINE_DEV3\My Documents\libs\gems\rails3.0>ruby -v
ruby 1.9.2p0 (2010-08-18) [i386-mingw32]
C:\Documents and Settings\MACHINE_DEV3\My Documents\libs\gems\rails3.0>
[/code]
Any idea ? Here is the gems list:
[code]
C:\Documents and Settings\MACHINE_DEV3\My Documents\libs\gems\rails3.0>gem list
*** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (3.0.0)
actionpack (3.0.0)
activemodel (3.0.0)
activerecord (3.0.0)
activerecord-oracle_enhanced-adapter (1.3.0)
activeresource (3.0.0)
activesupport (3.0.0)
arel (1.0.1)
builder (2.1.2)
bundler (1.0.0)
erubis (2.6.6)
gem_plugin (0.2.3)
i18n (0.4.1)
mail (2.2.5)
mime-types (1.16)
minitest (1.6.0)
mongrel (1.2.0.pre2 x86-mingw32)
mysql (2.8.1 x86-mswin32)
nifty-generators (0.4.1)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
rack-test (0.5.4)
rails (3.0.0)
railties (3.0.0)
rake (0.8.7)
rdoc (2.5.8)
ruby-oci8 (2.0.4 x86-mingw32)
sqlite-ruby (2.2.3 mswin32)
sqlite3-ruby (1.3.1 x86-mingw32)
thor (0.14.0)
treetop (1.4.8)
tzinfo (0.3.23)
C:\Documents and Settings\MACHINE_DEV3\My Documents\libs\gems\rails3.0>
[/code]
So the 'nifty' gem is on the list. Normal?
So, this is a tiny "issue" ... but really, nothing is telling me
what to expect from these things? What is the difference between
nifty_scaffold and normal scaffold?
I came across these in the wonderful advanced search railscast, and no doubt
experimentation will tell me something, but it would be nice if the README
at least gave a clue!
The rspec controller specs are now failing, because of their reliance on "integrate_views." The new verbiage is "render_views." Go figure.
all of a sudden I started getting this error when trying to run rake test
:
http://gist.github.com/151904.
The login.html.haml template still(?) uses :login instead of :username. Obviously this breaks login since the user-model has no :login attribute. (I guess most people don't use --haml with nifty_authentication?)
Rails 3 uses --template-engine
option to define template engine. It also can be set in application configuration.
In 'config/initializers/load_app_config.rb' first line. I think must be:
raw_config = File.read(RAILS_ROOT + "config/app_config.yml")
otherwise can't find file.
Have a nice day ;-)
Not 100% certain I have this right but I'm getting whitespace beneath the html/body. I know there's a fix but I'm not finding it at the moment.
In the nifty_layout
generator the javascript
helper will convert all values to a string except :defaults
. This can be a problem if one is using additional expansions. http://gist.github.com/160907
Instead the values should be carried over directly.
Redirect to root_url when index/show actions don't exist in nifty scaffold.
Currently the password is only saved on creation of the user. Instead it should be saved whenever the password attribute isn't blank so that one can provide an edit action where the password can change.
Your help file from Rails 3 (3.0.0 final; ruby 1.9.2-p0/head) says:
"Tests or specs are also generated depending
on if you have a "spec" directory or not."
However I had a spec/ directory and when I executed the following:
rails g nifty:scaffold Tag
I got a test/ directory created.
When I did:
(first: rm -rf test, then:)
rails g nifty:scaffold Tag --rspec
I instead got a spec/ dir... with the correct spec file generated.
See Markus Arike's fork for an example on how to add respond_to blocks for supporting XML and RSS/atom feeds.
when I run
script/generate nifty_authentication --haml --rspec --authlogic Account UserSession
it creates the model class UserSession but the file it is created in is named app/models/account_session.rb instead of user_session.rb
and later rails throws an error saying it is expecting the class AccountSession to exist (based on the filename)
I get
ActionView::Template::Error (undefined method `title' for #<#Class:0x00000104e331b8:0x00000104e31458>) on line #1 of /Users/user/src/blah/app/views/articles/index.html.erb:
1: <% title "Articles" %>
for the nifty:scaffold generator, this is with the latest gem version, rails 3 beta 3, and ruby 1.9.2dev
rails generate nifty:scaffold Article title:string description:text
For some reason I am unable to by pass this error. I have it added it to environment.rb as :
config.gem "nifty-generators", :version => '0.3.0'
am I doing something wrong or missing anything?
Thanks,
Arif Yayalar
I made a new project using rails new dummy -O
(as a test), added nifty-generators to my Gemfile, and bundle install
ed it. And then, sadly:
$ rails g nifty:scaffold metrics index
/Library/Ruby/Gems/1.8/gems/thor-0.13.7/lib/thor/core_ext/hash_with_indifferent_access.rb:26:in `[]=': can't modify frozen hash (TypeError)
from /Library/Ruby/Gems/1.8/gems/thor-0.13.7/lib/thor/core_ext/hash_with_indifferent_access.rb:26:in `[]='
from /Library/Ruby/Gems/1.8/gems/nifty-generators-0.4.0/lib/generators/nifty/scaffold/scaffold_generator.rb:51:in `initialize'
from /Library/Ruby/Gems/1.8/gems/thor-0.13.7/lib/thor/group.rb:36:in `new'
from /Library/Ruby/Gems/1.8/gems/thor-0.13.7/lib/thor/group.rb:36:in `start'
from /Library/Ruby/Gems/1.8/gems/thor-0.13.7/lib/thor/base.rb:378:in `start'
from /Library/Ruby/Gems/1.8/gems/thor-0.13.7/lib/thor/group.rb:29:in `start'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.0.beta4/lib/rails/generators.rb:164:in `invoke'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.0.beta4/lib/rails/commands/generate.rb:10
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:212:in `require'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:212:in `require'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:198:in `load_dependency'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:554:in `new_constants_in'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:198:in `load_dependency'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:212:in `require'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.0.beta4/lib/rails/commands.rb:17
from script/rails:6:in `require'
from script/rails:6
I just tried rails g scaffold_controller metrics
, and it also complained. No value provided for required options '--orm'
, it told me. Because that's nil when you don't have a database, I think?
ERROR: While executing gem ... (Errno::EINVAL)
Invalid argument - ./</cdesc-<.yaml
More often than not you should have attr_accessible in your models to restrict which attributes the user can set. This is a security problem in many apps. The model generated by nifty_scaffold should automatically add attr_accessible. For convenience it can default to including all columns mentioned in the generator. But at least the line is here for further customization and it is easy to remove if the model does not have an external user interface.
This is not a huge issue but I wanted to pass it on.
running this command generates a "pluralized" version of the name I pass it, and then I have to go and convert each file name and class / module declaration back to singular again. Maybe a flag to pass (similar to passing --haml) to keep it singular?
script/generate nifty_scaffold Home index
its not a huge issue but it is a hassle to go and rename several files and a folder, and then go and edit the controller and helper and functional test files to change the name to the singular version, and update the routes.rb.
Using:
nifty_generators 0.4.0
rails 2.3.8
I find it useless to link to the page being viewed
Well, I would like to have a feature to generate factory for the model to be generated instead of fixtures when using --shoulda option.
Has this been done in any forks of this nifty-generator?
If yes, link might be helpful for me.
rails generate nifty:scaffold product
...gems/thor-0.13.6/lib/thor/core_ext/hash_with_indifferent_access.rb:26:in `[]=': can't modify frozen hash (TypeError)
Bundler version 0.9.24
bundle show
Gems included by the bundle:
- abstract (1.0.0)
- actionmailer (3.0.0.beta3)
- actionpack (3.0.0.beta3)
- activemodel (3.0.0.beta3)
- activerecord (3.0.0.beta3)
- activeresource (3.0.0.beta3)
- activesupport (3.0.0.beta3)
- arel (0.3.3)
- builder (2.1.2)
- bundler (0.9.24)
- capistrano (2.5.18)
- devise (1.1.rc1)
- erubis (2.6.5)
- haml (3.0.4)
- highline (1.5.2)
- i18n (0.3.7)
- mail (2.2.1)
- memcache-client (1.8.3)
- mime-types (1.16)
- mocha (0.9.8)
- net-scp (1.0.2)
- net-sftp (2.0.4)
- net-ssh (2.0.22)
- net-ssh-gateway (1.0.1)
- nifty-generators (0.4.0)
- polyglot (0.3.1)
- rack (1.1.0)
- rack-mount (0.6.3)
- rack-test (0.5.4)
- rails (3.0.0.beta3)
- railties (3.0.0.beta3)
- rake (0.8.7)
- sqlite3-ruby (1.2.5)
- text-format (1.0.0)
- text-hyphen (1.0.0)
- thor (0.13.6)
- thoughtbot-shoulda (2.10.2)
- treetop (1.4.5)
- tzinfo (0.3.20)
- warden (0.10.5)
- will_paginate (3.0.pre)
There should be a --formtastic
option one could pass in nifty_scaffold or nifty_authentication which would use the simplified formtastic methods to generate form fields.
Looks like nifty scaffold generates some not so compatible rails 3 code :(
$ rails g nifty:scaffold user username:string email:string password:string --haml
DEPRECATION WARNING: f.error_messages was removed from Rails and is now available as a plugin. Please install it with rails plugin install git://github.com/rails/dynamic_form.git
. (called from block in _app_views_users__form_html_haml___3646798309746030193_38225180__1996457461889590104 at /usr/local/apache2/htdocs/ucravewiki/wp/app/views/users/_form.html.haml:2)
also a generator that used formtastic for forms would be awesome! Do you know if anyone is working on one?
There are quite a few nifty generators and it really fills up the generator listing. This also discourages me from adding more.
Instead maybe there could be a single nifty
generator which the first argument is the specific generator to use. For example:
script/generate nifty scaffold item name:string
If no generator is specified it could list them all with a short description.
$ script/generate nifty scaffold - ... layout - ... authentication - ...
Ruby: 1.9.2dev
Rails: 3.0b3
I've got nifty-generators added to my Gemfile. I successfully ran:
rails g nifty:layout
and:
rails g nifty:config
However when I tried to run:
rails g nifty:scaffold home
I got the following error: http://gist.github.com/381345
Thoughts?
The scaffold generator works fine and everything but what if I just change like one thing in the migration file (for example add another db column) -- is there a way to rerun the generator without retying everything int he console?
Add Rails 3 support. See this fork for an example. I plan to rewrite the generators along with the tests. I will try to keep the features roughly the same except for the nifty:scaffold
naming style so it matches the new Rails generators.
For the tests, I will look into using Cucumber and have it run the generator and run the generated test files in an example simple Rails project. See the Dr. Nic's generators for an example of this.
Rails 3 offers generator options where one can specify what tools they use (rspec, shoulda, factory girl, formtastic, mocha, etc.). Look for this and change the default generator options instead of simply looking for the "spec" directory like I am now.
It would be nice if there was an --authlogic
option to nifty_generator which would modify the output to be compatible with authoglic.
Create a clean Rails app and install devise on it
rails g devise:install
rails g devise User
rails g nifty:scaffold User
/home/michael/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/connection_adapters/sqlite_adapter.rb:295:in `table_structure': Could not find table 'users' (ActiveRecord::StatementInvalid)
from /home/michael/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/connection_adapters/sqlite_adapter.rb:186:in `columns'
from /home/michael/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/base.rb:679:in `columns'
from /home/michael/.rvm/gems/ruby-1.9.2-p0/gems/nifty-generators-0.4.1/lib/generators/nifty/scaffold/scaffold_generator.rb:194:in `model_columns_for_attributes'
from /home/michael/.rvm/gems/ruby-1.9.2-p0/gems/nifty-generators-0.4.1/lib/generators/nifty/scaffold/scaffold_generator.rb:55:in `initialize'
from /home/michael/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.3/lib/thor/group.rb:226:in `new'
from /home/michael/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.3/lib/thor/group.rb:226:in `dispatch'
from /home/michael/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.3/lib/thor/base.rb:389:in `start'
from /home/michael/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/generators.rb:163:in `invoke'
from /home/michael/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/commands/generate.rb:10:in `<top (required)>'
from /home/michael/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
from /home/michael/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `block in require'
from /home/michael/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `block in load_dependency'
from /home/michael/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:591:in `new_constants_in'
from /home/michael/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `load_dependency'
from /home/michael/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
from /home/michael/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/commands.rb:17:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
rails db:migrate followed by re-issuing the command works.
I'm following along Railscast 142. I used nifty generator to create a scaffold called "products." When I go to the path /products/new I get this error:
undefined method `products_index_path'
There was also another error on the "/products" path, where Rails complained that it couldn't find the path called "new_products_path". I changed products to product and it worked fine, but I don't know how to fix this one because it is thrown from this line:
<%= form_for @products do |f| %>
Any help would be great.
WC3 Markup Validation Service responds with this error msg related to nifty_layout's application layout template:
Line 2, Column 1: Missing xmlns attribute for element html. The value should be: http://www.w3.org/1999/xhtml
โ Many Document Types based on XML need a mandatory xmlns attribute on the root element. For example, the root element for XHTML might look like:Nifty Layout's generated markup:
Including or excluding xmlns="http://www.w3.org/1999/xhtml" changes css style rendering.
all of a sudden I started getting this error when trying to run +rake test+ -> http://gist.github.com/151904.
OSX 10.5.7
Ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]
Rails 2.3.2
newgem (1.5.1)
rubigen (1.4.0) since versions above 1.5 don't work -> http://github.com/jeffkreeftmeijer/nifty-generators/commit/fa208807b1926c4777c61bca295bcecfbeac7baf
thoughtbot-shoulda (2.10.2)
Hi everyone,
I tried installing nifty-generators today but I got an error message upon installing RI documentation.
ERROR: while executing gem .. (Errno::EINVAL)
Invalid argument - ./</cdesc-<.yaml
I'm running Rails on Vista, and I'm also a newbie. Any ideas on how to fix this?
I installed nifty-generators on Ubuntu 8.10, ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux], gem 1.3.4, but nifty_authentication generator is missing.
In line 32 of file rails_generators/nifty_scaffold/USAGE
, using the word 'affect', instead of 'effect', might be more appropriate.
Add the filter_parameter_logging :password
to the authentication module so it is applied to the application controller when included.
If you are experiencing this issue, it may have to do with the changes on how rails handles view helpers.
yield(:title) never returns nil anymore, it will always return "", which is nil.to_s.
With that said, the OR syntax ( || ) won't work.
I had to refactor it to work as expected with a change.
Usage in layouts.
ex: <title>Awesomeness :: <%= default_title "Welcome to my awesome site" %></title>
Usage in views.
ex: <% title "Have a look at our services" %>
module LayoutHelper
def default_title(default_title)
content_for?(:title) ? content_for(:title) : default_title
end
def title(page_title)
content_for(:title) { page_title.to_s }
end
end
It would be a very appreciated feature (at least by myself) if the nifty_scaffold generator could create a controller in a namespace.
Things to add:
What do you think ?
Hi, great gem - thanks! The specs do not work in Rspec 1.2.9 - for one reason at least, any_instance is no longer supported. Being that Rspec has it's own scaffold specs now, it would be great to just use those. If I get a second, I'll do a fork.
Just wanted to point out that their is a problem with the Rails3 branch with new the new update.
Its been resolved there.
Got this issue when trying to access http://localhost:3000/signup:
Routing Error
uninitialized constant ApplicationController::Authentication
From a GitHub message:
Add a --remarkable
option to support the Remarkable library.
See fork here: http://github.com/jtadeulopes/nifty-generators/tree/master
Fresh application, ran:
rails g nifty:layout
rails g nifty:authentication
Starting up the application and navigating to localhost:3000/users/new it gives the error:
"uninitialized constant ApplicationController::Authentication"
When I went in and started fiddling with the application_controller.rb changed the line:
include Authentication
to
require "authentication" #I'm kind of a newb
the page comes up, so I added a line to new.html.erb:
<%= logged_in? %>
and it throws an error for no function logged_in? being defined.
Then I changed the require statement back to:
include Authentication
and the page loads fine.
Then, when I restart the server, I get the uninitialized constant error again, and have to go through all these steps again.
Is this a rails issue with not loading modules correctly?
For the time being I guess I'll just copy/paste the methods into the application_controller.rb file like I had been doing before using nifty:authentication.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.