Disambiguating by breaking more conventions#3
Conversation
| <%= singular_table_name %>_to_show = <%= class_name.singularize %>.find(params[:id_to_display]) | ||
|
|
||
| render("<%= plural_table_name.underscore %>_templates/show.html.erb", :locals => { | ||
| :the_<%= singular_table_name.underscore %> => <%= singular_table_name %>_to_show |
There was a problem hiding this comment.
unexpected token tLT
unterminated string meets end of file
|
|
||
| def show | ||
| @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id]) | ||
| <%= singular_table_name %>_to_show = <%= class_name.singularize %>.find(params[:id_to_display]) |
| class <%= plural_table_name.camelize %>Controller < ApplicationController | ||
| def index | ||
| @<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all | ||
| all_<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all.order(:created_at => :desc) |
| @remaining_count = <%= class_name.singularize %>.count | ||
|
|
||
| render("<%= plural_table_name.underscore %>_templates/destroy_row.html.erb") | ||
| render("<%= singular_table_name.underscore %>_templates/destroy_row.html.erb", :locals => { |
There was a problem hiding this comment.
unexpected token tIDENTIFIER
unterminated string meets end of file
|
|
||
| <% unless skip_validation_alerts? -%> | ||
| redirect_to("/<%= @plural_table_name.underscore %>", :notice => "<%= singular_table_name.humanize %> deleted successfully.") | ||
| redirect_to("/<%= plural_table_name.underscore %>", :notice => "<%= singular_table_name.humanize %> deleted successfully.") |
There was a problem hiding this comment.
unexpected token tIDENTIFIER
unexpected token tRPAREN
|
|
||
| if save_status == true | ||
| redirect_to("/<%= @plural_table_name.underscore %>/#{@<%= singular_table_name.underscore %>.id}", :notice => "<%= singular_table_name.humanize %> updated successfully.") | ||
| redirect_to("/<%= plural_table_name.underscore %>/#{<%= singular_table_name.underscore %>_to_change.id}", :notice => "<%= singular_table_name.humanize %> updated successfully.") |
There was a problem hiding this comment.
unexpected token tLT
unexpected token tRPAREN
|
|
||
| <% attributes.each do |attribute| -%> | ||
| @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params[:<%= attribute.column_name %>] | ||
| <%= singular_table_name.underscore %>_to_change.<%= attribute.column_name %> = params["form_<%= attribute.column_name %>"] |
There was a problem hiding this comment.
unexpected token tIDENTIFIER
unexpected token tOP_ASGN
|
|
||
| def update_row | ||
| @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id_to_modify]) | ||
| <%= singular_table_name.underscore %>_to_change = <%= class_name.singularize %>.find(params["id_to_modify"]) |
|
|
||
| render("<%= plural_table_name.underscore %>_templates/edit_form.html.erb") | ||
| render("<%= singular_table_name.underscore %>_templates/edit_form.html.erb", :locals => { | ||
| :<%= singular_table_name.underscore %>_to_prefill => existing_<%= singular_table_name.underscore %> |
There was a problem hiding this comment.
unexpected token tOP_ASGN
unexpected token tIDENTIFIER
|
|
||
| def edit_form | ||
| @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:prefill_with_id]) | ||
| existing_<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params["prefill_with_id"]) |
22711f0 to
e594291
Compare
- Removing all instance variables to decouple variable name choices between actions that re-use templates, and to remove the additional cognitive load of learning what an instance variable is. Also, avoiding state is better practice anyway, IMO. - Using strings as keys to the `params` hash following the heuristic: "If we could change it to 'zebra' on a whim, then use a string; otherwise use a symbol." - Making variable and input names longer and more pedantic.
e594291 to
eebc1c7
Compare
| @remaining_count = <%= class_name.singularize %>.count | ||
|
|
||
| render("<%= plural_table_name.underscore %>_templates/destroy_row.html.erb") | ||
| render("<%= singular_table_name %>_templates/destroy_row.html.erb", :locals => { |
There was a problem hiding this comment.
unexpected token tIDENTIFIER
unterminated string meets end of file
|
|
||
| <% unless skip_validation_alerts? -%> | ||
| redirect_to("/<%= @plural_table_name.underscore %>", :notice => "<%= singular_table_name.humanize %> deleted successfully.") | ||
| redirect_to("/<%= plural_table_name %>", :notice => "<%= singular_table_name.humanize %> deleted successfully.") |
There was a problem hiding this comment.
unexpected token tIDENTIFIER
unexpected token tRPAREN
| <%= singular_table_name %>_to_delete = <%= class_name.singularize %>.find(params["id_to_remove"]) | ||
|
|
||
| @<%= singular_table_name.underscore %>.destroy | ||
| <%= singular_table_name %>_to_delete.destroy |
|
|
||
| def destroy_row | ||
| @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id_to_remove]) | ||
| <%= singular_table_name %>_to_delete = <%= class_name.singularize %>.find(params["id_to_remove"]) |
| redirect_to("/<%= plural_table_name %>/#{<%= singular_table_name %>_to_change.id}") | ||
| <% else -%> | ||
| render("<%= plural_table_name.underscore %>_templates/update_row.html.erb") | ||
| render("<%= singular_table_name %>_templates/update_row.html.erb", :locals => { |
There was a problem hiding this comment.
unexpected token tIDENTIFIER
unexpected token tLCURLY
|
|
||
| if save_status == true | ||
| redirect_to("/<%= @plural_table_name.underscore %>/#{@<%= singular_table_name.underscore %>.id}", :notice => "<%= singular_table_name.humanize %> updated successfully.") | ||
| redirect_to("/<%= plural_table_name %>/#{<%= singular_table_name %>_to_change.id}", :notice => "<%= singular_table_name.humanize %> updated successfully.") |
There was a problem hiding this comment.
unexpected token tLT
unexpected token tRPAREN
|
|
||
| <% attributes.each do |attribute| -%> | ||
| @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params[:<%= attribute.column_name %>] | ||
| <%= singular_table_name %>_to_change.<%= attribute.column_name %> = params["<%= attribute.column_name %>_from_form"] |
There was a problem hiding this comment.
unexpected token tIDENTIFIER
unexpected token tOP_ASGN
|
|
||
| def update_row | ||
| @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id_to_modify]) | ||
| <%= singular_table_name %>_to_change = <%= class_name.singularize %>.find(params["id_to_modify"]) |
|
|
||
| render("<%= plural_table_name.underscore %>_templates/edit_form.html.erb") | ||
| render("<%= singular_table_name %>_templates/edit_form.html.erb", :locals => { | ||
| :<%= singular_table_name %>_to_prefill => existing_<%= singular_table_name %> |
There was a problem hiding this comment.
unexpected token tOP_ASGN
unexpected token tIDENTIFIER
|
|
||
| def edit_form | ||
| @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:prefill_with_id]) | ||
| existing_<%= singular_table_name %> = <%= class_name.singularize %>.find(params["prefill_with_id"]) |
| @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id]) | ||
| id_of_<%= singular_table_name %>_to_show = params.fetch("id_to_display") | ||
|
|
||
| @<%= singular_table_name %>_to_show = <%= class_name.singularize %>.find(id_of_<%= singular_table_name %>_to_show) |
|
|
||
| def show | ||
| @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id]) | ||
| id_of_<%= singular_table_name %>_to_show = params.fetch("id_to_display") |
| id_of_<%= singular_table_name %>_to_show = params.fetch("id_to_display") | ||
|
|
||
| render("<%= plural_table_name.underscore %>_templates/show.html.erb") | ||
| @<%= singular_table_name %>_to_show = <%= class_name.singularize %>.find(id_of_<%= singular_table_name %>_to_show) |
|
|
||
| def show | ||
| @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id_to_display]) | ||
| id_of_<%= singular_table_name %>_to_show = params.fetch("id_to_display") |
| class <%= plural_table_name.camelize %>Controller < ApplicationController | ||
| def index | ||
| @<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all | ||
| @list_of_<%= plural_table_name %> = <%= class_name.singularize %>.all.order({ :created_at => :desc }) |
| %w(index show new_form create_row edit_form update_row destroy_row) | ||
| else | ||
| %w(index new_form edit_form show) | ||
| %w(index show new_form new_form_with_errors edit_form edit_form_with_errors) |
|
|
||
| template "specs/crud_spec.rb", "spec/features/crud_#{plural_table_name.underscore}_spec.rb" | ||
| template "specs/factories.rb", "spec/factories/#{plural_table_name.underscore}.rb" | ||
| template "specs/crud_spec.rb", "spec/features/crud_#{plural_table_name}_spec.rb" |
| available_views.each do |view| | ||
| filename = view_filename_with_extensions(view) | ||
| template filename, File.join("app/views", "#{plural_table_name}_templates", File.basename(filename)) | ||
| template filename, File.join("app/views", "#{singular_table_name}_templates", File.basename(filename)) |
| template "controllers/read_only_controller.rb", "app/controllers/#{plural_table_name}_controller.rb" | ||
| else | ||
| template "controllers/controller.rb", "app/controllers/#{plural_table_name.underscore}_controller.rb" | ||
| template "controllers/controller.rb", "app/controllers/#{plural_table_name}_controller.rb" |
|
|
||
| if read_only? | ||
| template "controllers/read_only_controller.rb", "app/controllers/#{plural_table_name.underscore}_controller.rb" | ||
| template "controllers/read_only_controller.rb", "app/controllers/#{plural_table_name}_controller.rb" |
* Add github login * #3 - Fixed failing test * #3 - Fixed other test cases * #3 - Minor changes * #3 - Indentation fixes * #3 Added .rubocop.yml and fixed rubocop issues * #3 - Test cases for https://github.com/firstdraft/ideas/pull/3 * #3 - CicleCi add minitest_globs and fixed rubocop issues * #3 - Added bootswatch paper theme * #3 - Turn off hound ci for js, css * we do not recommend using capybara * added database yml to gitignore * added database yml sample file for postgresqlapp * #3 - Removed rspec completely * #3 - Remove Factory Girl and instead uses fixtures * #3 - Updated CircleCi.yml and modified setup script * #3 - Added database.yml.ci * #3 - Review comments changes
between actions that re-use templates, and to remove the additional
cognitive load of learning what an instance variable is. Also,
avoiding state is better practice anyway, IMO.
paramshash following the heuristic:"If we could change it to 'zebra' on a whim, then use a string;
otherwise use a symbol."