aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/generators
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2013-01-10 20:21:22 +0100
committerDavid Heinemeier Hansson <david@loudthinking.com>2013-01-10 20:21:22 +0100
commit3bfd99defb559af0b017ee920ca714aa1e367fdd (patch)
treedefb61ccd22fdecf7ac41d48dea421ad6e16852a /railties/lib/rails/generators
parent6572499b07cf740a548883118de61bb31031feea (diff)
downloadrails-3bfd99defb559af0b017ee920ca714aa1e367fdd.tar.gz
rails-3bfd99defb559af0b017ee920ca714aa1e367fdd.tar.bz2
rails-3bfd99defb559af0b017ee920ca714aa1e367fdd.zip
Include jbuilder by default and rely on its scaffold generator to show json API. The default scaffold will now just create HTML if the user actively opts out of jbuilder
Diffstat (limited to 'railties/lib/rails/generators')
-rw-r--r--railties/lib/rails/generators/rails/app/templates/Gemfile6
-rw-r--r--railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb7
-rw-r--r--railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb9
-rw-r--r--railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb66
4 files changed, 13 insertions, 75 deletions
diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile
index c4846b2c11..2b80896c27 100644
--- a/railties/lib/rails/generators/rails/app/templates/Gemfile
+++ b/railties/lib/rails/generators/rails/app/templates/Gemfile
@@ -9,12 +9,12 @@ source 'https://rubygems.org'
<%= assets_gemfile_entry %>
<%= javascript_gemfile_entry -%>
+# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
+gem 'jbuilder'
+
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
-# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
-# gem 'jbuilder'
-
# Use unicorn as the app server
# gem 'unicorn'
diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
index dd636ed3cf..9a7ea1f657 100644
--- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
+++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
@@ -9,13 +9,8 @@ module Rails
class_option :stylesheets, type: :boolean, desc: "Generate Stylesheets"
class_option :stylesheet_engine, desc: "Engine for Stylesheets"
- class_option :html, type: :boolean, default: true,
- desc: "Generate a scaffold with HTML output"
-
def handle_skip
- if !options[:html] || !options[:stylesheets]
- @options = @options.merge(stylesheet_engine: false)
- end
+ @options = @options.merge(stylesheet_engine: false) if !options[:stylesheets]
end
hook_for :scaffold_controller, required: true
diff --git a/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb b/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb
index 32fa54a362..4f36b612ae 100644
--- a/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb
+++ b/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb
@@ -10,17 +10,8 @@ module Rails
class_option :orm, banner: "NAME", type: :string, required: true,
desc: "ORM to generate the controller for"
- class_option :html, type: :boolean, default: true,
- desc: "Generate a scaffold with HTML output"
-
argument :attributes, type: :array, default: [], banner: "field:type field:type"
- def handle_skip
- unless options[:html]
- @options = @options.merge(template_engine: false, helper: false)
- end
- end
-
def create_controller_files
template "controller.rb", File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb")
end
diff --git a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb
index e11d357314..6f7eb07229 100644
--- a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb
+++ b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb
@@ -7,95 +7,47 @@ class <%= controller_class_name %>Controller < ApplicationController
before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
# GET <%= route_url %>
- # GET <%= route_url %>.json
def index
@<%= plural_table_name %> = <%= orm_class.all(class_name) %>
-
- respond_to do |format|
- <%- if options[:html] -%>
- format.html # index.html.erb
- <%- end -%>
- format.json { render json: <%= "@#{plural_table_name}" %> }
- end
end
# GET <%= route_url %>/1
- # GET <%= route_url %>/1.json
def show
- respond_to do |format|
- <%- if options[:html] -%>
- format.html # show.html.erb
- <%- end -%>
- format.json { render json: <%= "@#{singular_table_name}" %> }
- end
end
- <%- if options[:html] -%>
# GET <%= route_url %>/new
- # GET <%= route_url %>/new.json
def new
@<%= singular_table_name %> = <%= orm_class.build(class_name) %>
-
- respond_to do |format|
- format.html # new.html.erb
- format.json { render json: <%= "@#{singular_table_name}" %> }
- end
end
# GET <%= route_url %>/1/edit
def edit
end
- <%- end -%>
# POST <%= route_url %>
- # POST <%= route_url %>.json
def create
@<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
- respond_to do |format|
- if @<%= orm_instance.save %>
- <%- if options[:html] -%>
- format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %> }
- <%- end -%>
- format.json { render json: <%= "@#{singular_table_name}" %>, status: :created, location: <%= "@#{singular_table_name}" %> }
- else
- <%- if options[:html] -%>
- format.html { render action: "new" }
- <%- end -%>
- format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
- end
+ if @<%= orm_instance.save %>
+ redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %>
+ else
+ render action: "new"
end
end
# PATCH/PUT <%= route_url %>/1
- # PATCH/PUT <%= route_url %>/1.json
def update
- respond_to do |format|
- if @<%= orm_instance.update("#{singular_table_name}_params") %>
- <%- if options[:html] -%>
- format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> }
- <%- end -%>
- format.json { head :no_content }
- else
- <%- if options[:html] -%>
- format.html { render action: "edit" }
- <%- end -%>
- format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
- end
+ if @<%= orm_instance.update("#{singular_table_name}_params") %>
+ redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %>
+ else
+ render action: "edit"
end
end
# DELETE <%= route_url %>/1
- # DELETE <%= route_url %>/1.json
def destroy
@<%= orm_instance.destroy %>
-
- respond_to do |format|
- <%- if options[:html] -%>
- format.html { redirect_to <%= index_helper %>_url }
- <%- end -%>
- format.json { head :no_content }
- end
+ redirect_to <%= index_helper %>_url
end
private