Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nowhereman/285963 to your computer and use it in GitHub Desktop.
Save nowhereman/285963 to your computer and use it in GitHub Desktop.
Patch nifty scaffold generator to add --skip-actions option for controller only. Patch nifty layout generator to used jQuery and Jammit
# Use Inherited Resources controller instead of Application controller
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
--- /opt/ree/lib/ruby/gems/1.8/gems/nifty-generators-0.3.0/rails_generators/nifty_scaffold/templates/controller.rb
+++ /home/nowhereman/project1/vendor/generators/nifty_scaffold/templates/controller.rb
@@ -1,3 +1,4 @@
-class <%= plural_class_name %>Controller < ApplicationController
+class <%= plural_class_name %>Controller < InheritedResources::Base
+ respond_to :html, :xml, :json
<%= controller_methods :actions %>
end
# Support jQuery and jammit file in nifty layout with ERB template
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
--- /opt/ree/lib/ruby/gems/1.8/gems/nifty-generators-0.3.0/rails_generators/nifty_layout/templates/layout.html.erb
+++ /home/nowhereman/project1/vendor/generators/nifty_layout/templates/layout.html.erb
@@ -4,6 +4,9 @@
<head>
<title><%%= h(yield(:title) || "Untitled") %></title>
<%%= stylesheet_link_tag '<%= file_name %>' %>
+ <%= include_javascripts :workspace %>
+ <%= include_templates :everything %>
+ <%= javascript_tag "var AUTH_TOKEN = #{form_authenticity_token.inspect};" if protect_against_forgery? %>
<%%= yield(:head) %>
</head>
<body>
# Patch Nifty Scaffold generator to add --skip-actions option in controller but keep actions views.
# Very useful if you use Inherited Resources gem/plugin in your Rails project !
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
--- /opt/ree/lib/ruby/gems/1.8/gems/nifty-generators-0.3.0/rails_generators/nifty_scaffold/nifty_scaffold_generator.rb
+++ /home/nowhereman/project1/vendor/generators/nifty_scaffold/nifty_scaffold_generator.rb
@@ -126,10 +126,12 @@
end
def controller_methods(dir_name)
+ unless options[:skip_actions]
controller_actions.map do |action|
read_template("#{dir_name}/#{action}.rb")
end.join(" \n").strip
end
+ end
def render_form
if form_partial?
@@ -206,6 +208,7 @@
opt.on("--skip-migration", "Don't generate migration file for model.") { |v| options[:skip_migration] = v }
opt.on("--skip-timestamps", "Don't add timestamps to migration file.") { |v| options[:skip_timestamps] = v }
opt.on("--skip-controller", "Don't generate controller, helper, or views.") { |v| options[:skip_controller] = v }
+ opt.on("--skip-actions", "Don't generate controller actions, useful for Inherited resources plugin.") { |v| options[:skip_actions] = v }
opt.on("--invert", "Generate all controller actions except these mentioned.") { |v| options[:invert] = v }
opt.on("--haml", "Generate HAML views instead of ERB.") { |v| options[:haml] = v }
opt.on("--testunit", "Use test/unit for test files.") { options[:test_framework] = :testunit }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment