diff --git a/.rubocop.yml b/.rubocop.yml index cd732d97..db52e7eb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,6 +4,7 @@ # Project setup: require: ./extras/prohibit_safe_navigation +require: ./extras/prohibit_form_for_and_form_tag Rails: Enabled: true AllCops: diff --git a/.ruumba.yml b/.ruumba.yml new file mode 100644 index 00000000..93d16a46 --- /dev/null +++ b/.ruumba.yml @@ -0,0 +1,9 @@ +require: ./extras/prohibit_form_for_and_form_tag + +AllCops: + DisabledByDefault: true + +Style/DisallowFormForandFormTag: + Enabled: true + Include: + - '**/*.erb' diff --git a/Gemfile b/Gemfile index 36ddd852..fadeb279 100644 --- a/Gemfile +++ b/Gemfile @@ -37,6 +37,8 @@ gem "oauth" # for twitter-posting bot gem "mail" # for parsing incoming mail gem "sitemap_generator" # for better search engine indexing +gem "ruumba" + group :test, :development do gem 'bullet' gem 'capybara' diff --git a/Gemfile.lock b/Gemfile.lock index 220bdd40..06f37a5c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -196,6 +196,8 @@ GEM i18n ruby-progressbar (1.10.0) ruby_dep (1.5.0) + ruumba (0.1.8) + rubocop scenic (1.4.1) activerecord (>= 4.0.0) railties (>= 4.0.0) @@ -261,6 +263,7 @@ DEPENDENCIES rspec-rails rubocop rubocop-rspec + ruumba scenic scenic-mysql_adapter sitemap_generator diff --git a/app/views/comments/_commentbox.html.erb b/app/views/comments/_commentbox.html.erb index 08844a01..2fdc99e7 100644 --- a/app/views/comments/_commentbox.html.erb +++ b/app/views/comments/_commentbox.html.erb @@ -1,20 +1,19 @@
-<%= form_for comment, -:html => { :id => "edit_comment_#{comment.short_id}" } do |f| %> +<%= form_with url: comment, :id => "edit_comment_#{comment.short_id}" do |f| %> <% if comment.errors.any? %> <%= errors_for comment %> <% end %> - <%= hidden_field_tag "story_id", comment.story.short_id %> + <%= f.hidden_field "story_id", :value => comment.story.short_id %> <% if comment.parent_comment %> - <%= hidden_field_tag "parent_comment_short_id", + <%= f.hidden_field "parent_comment_short_id", comment.parent_comment.short_id %> <% end %>
- <%= text_area_tag "comment", comment.comment, :rows => 5, + <%= f.text_area "comment", :body => comment.comment, :rows => 5, :disabled => !@user, :placeholder => (@user ? "" : "You must be logged in to leave a comment.") %> @@ -32,21 +31,21 @@ data-shortid="<%= comment.short_id if comment.persisted? %>">
<% end %> - <%= submit_tag "#{comment.new_record?? "Post" : "Update"}", + <%= f.submit "#{comment.new_record?? "Post" : "Update"}", :class => "comment-post", :disabled => !@user %>   - <%= button_tag "Preview", :class => "comment-preview", + <%= f.button "Preview", :class => "comment-preview", :type => "button", :disabled => !@user %> <% if comment.persisted? || comment.parent_comment_id %>   - <%= button_tag "Cancel", :class => "comment-cancel", + <%= f.button "Cancel", :class => "comment-cancel", :type => "button" %> <% end %> <% if @user && @user.wearable_hats.any? %>
Put on hat: - <%= select_tag "hat_id", + <%= f.select "hat_id", options_from_collection_for_select(@user.wearable_hats, "id", "hat", comment.hat_id), :include_blank => true %>
diff --git a/app/views/filters/index.html.erb b/app/views/filters/index.html.erb index 6d3fe648..a39db3f3 100644 --- a/app/views/filters/index.html.erb +++ b/app/views/filters/index.html.erb @@ -16,7 +16,7 @@

<% end %> - <%= form_tag "/filters", :method => :post do %> + <%= form_with url: "/filters", :method => :post do |f| %> @@ -41,7 +41,7 @@ <% end %>
Hide

- <%= submit_tag "Save Filters" %> + <%= f.submit "Save Filters" %>

<% end %>
diff --git a/app/views/hats/build_request.html.erb b/app/views/hats/build_request.html.erb index 9f1abc54..09baff4b 100644 --- a/app/views/hats/build_request.html.erb +++ b/app/views/hats/build_request.html.erb @@ -36,7 +36,7 @@ verification of project association.

- <%= form_for @hat_request, :url => create_hat_request_path do |f| %> + <%= form_with model: @hat_request, :url => create_hat_request_path do |f| %>

<%= f.label :hat, "Hat:" %> <%= f.text_field :hat, :size => 20, diff --git a/app/views/hats/requests_index.html.erb b/app/views/hats/requests_index.html.erb index 5a9fdc87..a662ac1c 100644 --- a/app/views/hats/requests_index.html.erb +++ b/app/views/hats/requests_index.html.erb @@ -11,7 +11,7 @@


<% end %> - <%= form_for hr, :url => approve_hat_request_url(:id => hr), + <%= form_with model: hr, :url => approve_hat_request_url(:id => hr), :method => :post do |f| %>

@@ -42,20 +42,20 @@

- <%= submit_tag "Approve Hat Request" %> + <%= f.submit "Approve Hat Request" %>

<% end %>

or

- <%= form_for hr, :url => reject_hat_request_url(:id => hr), + <%= form_with model: hr, :url => reject_hat_request_url(:id => hr), :method => :post do |f| %>
<%= f.label :link, "Reason:", :class => "required" %> <%= f.text_area :rejection_comment, :rows => 4 %>

- <%= submit_tag "Reject Hat Request" %> + <%= f.submit "Reject Hat Request" %>

<% end %> <% end %> diff --git a/app/views/invitations/build.html.erb b/app/views/invitations/build.html.erb index 753e9269..f20caf68 100644 --- a/app/views/invitations/build.html.erb +++ b/app/views/invitations/build.html.erb @@ -16,7 +16,7 @@ shown to any other users (except moderators).

- <%= form_for @invitation_request, + <%= form_with model: @invitation_request, :url => create_invitation_by_request_path do |f| %>

<%= f.label :name, "Name (not username):" %> @@ -36,7 +36,7 @@

- <%= submit_tag "Request Invitation" %> + <%= f.submit "Request Invitation" %>

<% end %> diff --git a/app/views/invitations/index.html.erb b/app/views/invitations/index.html.erb index f13802bf..a1b98a59 100644 --- a/app/views/invitations/index.html.erb +++ b/app/views/invitations/index.html.erb @@ -26,14 +26,14 @@ <%= ir.email %> <% end %> <%= raw ir.markeddown_memo %> - <%= form_tag send_invitation_for_request_path do %> - <%= hidden_field_tag "code", ir.code %> - <%= submit_tag "Send Invitation", :data => { :confirm => "Are " << + <%= form_with url: send_invitation_for_request_path do |f| %> + <%= f.hidden_field "code", :value => ir.code %> + <%= f.submit "Send Invitation", :data => { :confirm => "Are " << "you sure you want to invite this person and remove this request?" } %> <% end %> - <%= form_tag delete_invitation_request_path do %> - <%= hidden_field_tag "code", ir.code %> - <%= submit_tag "Delete", :data => { :confirm => "Are you sure " << + <%= form_with url: delete_invitation_request_path do |f| %> + <%= f.hidden_field "code", :value => ir.code %> + <%= f.submit "Delete", :data => { :confirm => "Are you sure " << "you want to delete this request?" } %> <% end %> diff --git a/app/views/login/forgot_password.html.erb b/app/views/login/forgot_password.html.erb index 0f7653e3..e0e6ee51 100644 --- a/app/views/login/forgot_password.html.erb +++ b/app/views/login/forgot_password.html.erb @@ -8,13 +8,13 @@ below and instructions will be e-mailed to you.

- <%= form_tag reset_password_path do %> - <%= label_tag :email, "E-mail or Username:" %> - <%= text_field_tag :email, "", :size => 30 %> + <%= form_with url: reset_password_path do |f| %> + <%= f.label :email, "E-mail or Username:" %> + <%= f.text_field :email, :size => 30 %>

- <%= submit_tag "Reset Password" %> + <%= f.submit "Reset Password" %>

<% end %> diff --git a/app/views/login/index.html.erb b/app/views/login/index.html.erb index 46da8a73..dedd6c23 100644 --- a/app/views/login/index.html.erb +++ b/app/views/login/index.html.erb @@ -8,19 +8,19 @@ The site is currently in read-only mode for maintenance.

<% else %> - <%= form_tag login_path do %> + <%= form_with url: login_path do |form| %>

- <%= label_tag :email, "E-mail or Username:" %> - <%= text_field_tag :email, "", :size => 30, :autofocus => "autofocus" %> + <%= form.label :email, "E-mail or Username:" %> + <%= form.text_field :email, :size => 30, :autofocus => "autofocus" %>
- <%= label_tag :password, "Password:" %> - <%= password_field_tag :password, "", :size => 30 %> + <%= form.label :password, "Password:" %> + <%= form.password_field :password, :size => 30 %>

- <%= submit_tag "Login" %> + <%= form.submit "Login" %>

diff --git a/app/views/login/set_new_password.html.erb b/app/views/login/set_new_password.html.erb index dd9925ff..8a1b2c82 100644 --- a/app/views/login/set_new_password.html.erb +++ b/app/views/login/set_new_password.html.erb @@ -3,26 +3,26 @@ Set New Password - <%= form_tag set_new_password_path, { :autocomplete => "off" } do %> + <%= form_with url: set_new_password_path, :autocomplete => "off" do |f| %> <%= error_messages_for(@reset_user) %> - <%= hidden_field_tag "token", params[:token] %> + <%= f.hidden_field "token", :value => params[:token] %>

- <%= label_tag :username, "Username:" %> + <%= f.label :username, "Username:" %> <%= @reset_user.username %>
- <%= label_tag :password, "New Password:" %> - <%= password_field_tag :password, "", :size => 30 %> + <%= f.label :password, "New Password:" %> + <%= f.password_field :password, :size => 30 %>
- <%= label_tag :password_confirmation, "(Again):" %> - <%= password_field_tag :password_confirmation, "", :size => 30 %> + <%= f.label :password_confirmation, "(Again):" %> + <%= f.password_field :password_confirmation, :size => 30 %>

- <%= submit_tag "Set New Password" %> + <%= f.submit "Set New Password" %>

<% end %> diff --git a/app/views/login/twofa.html.erb b/app/views/login/twofa.html.erb index 5ebc731d..5cd4a25b 100644 --- a/app/views/login/twofa.html.erb +++ b/app/views/login/twofa.html.erb @@ -3,20 +3,20 @@ Login - Two Factor Authentication - <%= form_tag twofa_login_url do %> + <%= form_with url: twofa_login_url do |f| %>

Enter the current TOTP code from your TOTP application:

- <%= label_tag :totp_code, "TOTP Code:" %> - <%= number_field_tag :totp_code, "", :size => 10, :autocomplete => "off", + <%= f.label :totp_code, "TOTP Code:" %> + <%= f.number_field :totp_code, :size => 10, :autocomplete => "off", :autofocus => true, :class => "totp_code" %>

- <%= submit_tag "Login" %> + <%= f.submit "Login" %>

<% end %> diff --git a/app/views/messages/_form.html.erb b/app/views/messages/_form.html.erb index 75946c37..935e7b11 100644 --- a/app/views/messages/_form.html.erb +++ b/app/views/messages/_form.html.erb @@ -1,8 +1,8 @@ -<%= form_for new_message, :method => :post do |f| %> +<%= form_with model: @new_message, url: new_message, :method => :post do |f| %> <%= error_messages_for @new_message %> <% if replying %> - <%= f.hidden_field :recipient_username %> + <%= f.hidden_field :recipient_username %> <% else %>
<%= f.label :recipient_username, "To:", :class => "required" %> @@ -38,6 +38,6 @@

- <%= submit_tag replying ? "Reply" : "Send Message" %> + <%= f.submit replying ? "Reply" : "Send Message" %>
<% end %> diff --git a/app/views/messages/index.html.erb b/app/views/messages/index.html.erb index 2ddbf612..ce302648 100644 --- a/app/views/messages/index.html.erb +++ b/app/views/messages/index.html.erb @@ -23,7 +23,7 @@
<% if @messages.any? %> - <%= form_tag batch_delete_messages_path do %> + <%= form_with url: batch_delete_messages_path do |f| %>
<%= check_box_tag "delete_all", @@ -58,7 +58,7 @@ <% end %>

- <%= submit_tag "Delete Selected" %> + <%= f.submit "Delete Selected" %>

<% end %> <% else %> diff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erb index 4a6fc643..2d2585da 100644 --- a/app/views/messages/show.html.erb +++ b/app/views/messages/show.html.erb @@ -33,21 +33,21 @@
- <%= form_tag message_path(@message.short_id), :method => :delete do %> - <%= submit_tag "Delete Message" %> + <%= form_with url: message_path(@message.short_id), :method => :delete do |f| %> + <%= f.submit "Delete Message" %> <% end %>
- <%= form_tag message_keep_as_new_path(@message.short_id), :method => :post do %> - <%= submit_tag "Keep As New" %> + <%= form_with url: message_keep_as_new_path(@message.short_id), :method => :post do |f| %> + <%= f.submit "Keep As New" %> <% end %>
<% if @user.is_moderator? %>
- <%= form_tag message_mod_note_path(@message.short_id), :method => :post do %> - <%= submit_tag "ModNote" %> + <%= form_with url: message_mod_note_path(@message.short_id), :method => :post do |f| %> + <%= f.submit "ModNote" %> <% end %>
<% end %> diff --git a/app/views/mod_notes/index.html.erb b/app/views/mod_notes/index.html.erb index 5d296dec..df20011c 100644 --- a/app/views/mod_notes/index.html.erb +++ b/app/views/mod_notes/index.html.erb @@ -1,10 +1,10 @@ <%= render partial: 'mod/nav' %> -<%= form_tag mod_notes_path, method: :get do |f| %> +<%= form_with url: mod_notes_path, method: :get do |f| %>
- <%= submit_tag 'Filter' %> + <%= f.submit 'Filter' %>
<% end %> diff --git a/app/views/moderations/index.html.erb b/app/views/moderations/index.html.erb index 7b051e91..2c5228f2 100644 --- a/app/views/moderations/index.html.erb +++ b/app/views/moderations/index.html.erb @@ -3,9 +3,9 @@ Moderation Log
- <%= form_tag(moderations_path, :method => :get) do |f| %> + <%= form_with url: moderations_path, :method => :get do |f| %> - <%= select_tag 'moderator', options_for_select(@moderators, @moderator) %> + <%= f.select 'moderator', options_for_select(@moderators, @moderator) %> <% @what.each do |type, checked| %> <%= check_box_tag "what[#{type}]", type, checked %> diff --git a/app/views/search/index.html.erb b/app/views/search/index.html.erb index fb325e7a..bfe41530 100644 --- a/app/views/search/index.html.erb +++ b/app/views/search/index.html.erb @@ -3,9 +3,9 @@ Search - <%= form_tag "/search", :method => :get do %> + <%= form_with url: "/search", :method => :get do |f| %>
- <%= text_field_tag "q", @search.q, { :size => 40 }. + <%= f.text_field "q", { :value => @search.q, :size => 40 }. merge(@search.q.present? ? {} : { :autofocus => "autofocus" }) %>
@@ -13,29 +13,29 @@
- <%= radio_button_tag "what", "stories", @search.what == "stories" %> + <%= f.radio_button "what", "stories", :checked => @search.what == "stories" %>   - <%= radio_button_tag "what", "comments", @search.what == "comments" %> + <%= f.radio_button "what", "comments", :checked => @search.what == "comments" %>
- <%= radio_button_tag "order", "relevance", @search.order == "relevance" %> + <%= f.radio_button "order", "relevance", :checked => @search.order == "relevance" %>   - <%= radio_button_tag "order", "newest", @search.order == "newest" %> + <%= f.radio_button "order", "newest", :checked => @search.order == "newest" %>   - <%= radio_button_tag "order", "points", @search.order == "points" %> + <%= f.radio_button "order", "points", :checked => @search.order == "points" %>
<% end %> diff --git a/app/views/settings/index.html.erb b/app/views/settings/index.html.erb index 40e6eae4..fb54bd8d 100644 --- a/app/views/settings/index.html.erb +++ b/app/views/settings/index.html.erb @@ -10,8 +10,8 @@ Account Settings (View Profile) - <%= form_for @edit_user, :url => settings_path, :method => :post, - :html => { :id => "edit_user" } do |f| %> + <%= form_with :model => @edit_user, :url => settings_path, :method => :post, + :id => "edit_user" do |f| %> <%= error_messages_for f.object %>
@@ -23,9 +23,9 @@
- <%= label_tag :current_password, "Current Password:", + <%= f.label :current_password, "Current Password:", :class => "required" %> - <%= password_field_tag :current_password, nil, :size => 40 %> + <%= f.password_field :current_password, :name => "current_password", :size => 30 %>
@@ -74,7 +74,7 @@
- <%= label_tag :gravatar, + <%= f.label :gravatar, raw("Gravatar:"), :class => "required" %> @@ -86,7 +86,7 @@ <% if Pushover.enabled? %>
- <%= label_tag :pushover_user_key, + <%= f.label :pushover_user_key, raw("Pushover:"), :class => "required" %> @@ -104,7 +104,7 @@ <% if Github.enabled? %>
- <%= label_tag :github_username, + <%= f.label :github_username, raw("GitHub:"), :class => "required" %> <% if @edit_user.github_username.present? %> @@ -122,7 +122,7 @@ <% if Twitter.enabled? %>
- <%= label_tag :twitter_username, + <%= f.label :twitter_username, raw("Twitter:"), :class => "required" %> @@ -301,8 +301,8 @@
- <%= form_for @edit_user, :url => delete_account_path, :method => :post, - :html => { :id => "delete_user" } do |f| %> + <%= form_with :model => @edit_user, :url => delete_account_path, :method => :post, + :id => "delete_user" do |f| %>
Delete Account
@@ -329,10 +329,10 @@
<%= f.label :i_am_sure, "I am sure:", :class => "required" %> - <%= check_box_tag :i_am_sure %> + <%= f.check_box :i_am_sure %>
<%= f.label :disown, "Disown Comments:" %> - <%= check_box_tag :disown %> (optional) + <%= f.check_box :disown %> (optional)
<%= f.submit "Yes, Delete My Account", :class => "deletion" %> <% end %> diff --git a/app/views/settings/twofa.html.erb b/app/views/settings/twofa.html.erb index 66fb9582..55b7cdf3 100644 --- a/app/views/settings/twofa.html.erb +++ b/app/views/settings/twofa.html.erb @@ -6,7 +6,7 @@ <%= @title %>
- <%= form_for @user, :url => twofa_auth_url, :method => :post do |f| %> + <%= form_with :model => @user, :url => twofa_auth_url, :method => :post do |f| %>

<% if @user.has_2fa? %> To turn off two-factor authentication for your account, enter your @@ -24,9 +24,9 @@

<% if @user.has_2fa? %> - <%= submit_tag "Disable Two-Factor Authentication" %> + <%= f.submit "Disable Two-Factor Authentication" %> <% else %> - <%= submit_tag "Continue" %> + <%= f.submit "Continue" %> <% end %> <% end %>

diff --git a/app/views/settings/twofa_verify.html.erb b/app/views/settings/twofa_verify.html.erb index fba9cb50..d60fd303 100644 --- a/app/views/settings/twofa_verify.html.erb +++ b/app/views/settings/twofa_verify.html.erb @@ -6,19 +6,19 @@ <%= @title %>
- <%= form_tag twofa_update_url do %> + <%= form_with url: twofa_update_url do |f| %>

To enable Two-Factor Authentication on your account using your new TOTP secret, enter the six-digit code from your TOTP application:

- <%= label_tag :totp_code, "TOTP Code:", :class => "required" %> - <%= number_field_tag :totp_code, "", :size => 10, :autocomplete => "off", + <%= f.label :totp_code, "TOTP Code:", :class => "required" %> + <%= f.number_field :totp_code, :size => 10, :autocomplete => "off", :autofocus => true, :class => "totp_code" %>

- <%= submit_tag "Verify and Enable" %> + <%= f.submit "Verify and Enable" %> <% end %>

diff --git a/app/views/signup/invited.html.erb b/app/views/signup/invited.html.erb index 3a7f3010..93c67ca7 100644 --- a/app/views/signup/invited.html.erb +++ b/app/views/signup/invited.html.erb @@ -3,7 +3,7 @@ Create an Account - <%= form_for @new_user, { :url => signup_path } do |f| %> + <%= form_with model: @new_user, :url => signup_path do |f| %>

To create a new account, enter your e-mail address and a password. Your e-mail address will never be shown to users and will only be used @@ -14,7 +14,7 @@ <%= error_messages_for(@new_user) %> <% if not Rails.application.open_signups? %> - <%= hidden_field_tag "invitation_code", @invitation.code %> + <%= f.hidden_field "invitation_code", :value => @invitation.code %>

<%= f.label :invitation, "Invited By:", :class => "required" %> @@ -75,7 +75,7 @@

- <%= submit_tag "Signup" %> + <%= f.submit "Signup" %>

<% end %> diff --git a/app/views/stories/_form_errors.html.erb b/app/views/stories/_form_errors.html.erb index 1ba03765..7aeb9d51 100644 --- a/app/views/stories/_form_errors.html.erb +++ b/app/views/stories/_form_errors.html.erb @@ -17,7 +17,7 @@ <% if defined?(f) %> <%= f.hidden_field :seen_previous %> <% else %> - <%= form_for story do |f| %> + <%= form_with model: story do |f| %> <%= f.hidden_field :seen_previous %> <% end %> <% end %> diff --git a/app/views/stories/edit.html.erb b/app/views/stories/edit.html.erb index be94354f..1225e8bc 100644 --- a/app/views/stories/edit.html.erb +++ b/app/views/stories/edit.html.erb @@ -3,8 +3,8 @@ Edit Story - <%= form_for @story, :url => story_path(@story.short_id), - :method => :put, :html => { :id => "edit_story" } do |f| %> + <%= form_with model: @story, :url => story_path(@story.short_id), + :method => :put, :id => "edit_story" do |f| %> <%= render :partial => "stories/form", :locals => { :story => @story, :f => f } %> @@ -43,7 +43,7 @@ Markdown formatting available - <%= submit_tag "Save" %> + <%= f.submit "Save" %> <% if @story.is_gone? && @story.is_undeletable_by_user?(@user) %>   |   diff --git a/app/views/stories/new.html.erb b/app/views/stories/new.html.erb index 3f077d38..4efb9093 100644 --- a/app/views/stories/new.html.erb +++ b/app/views/stories/new.html.erb @@ -4,7 +4,7 @@
- <%= form_for @story do |f| %> + <%= form_with model: @story do |f| %> <%= render :partial => "stories/form", :locals => { :story => @story, :f => f } %>

@@ -15,7 +15,7 @@ Markdown formatting available
- <%= submit_tag "Submit" %> + <%= f.submit "Submit" %>   diff --git a/app/views/stories/suggest.html.erb b/app/views/stories/suggest.html.erb index 36c6d9c2..af001997 100644 --- a/app/views/stories/suggest.html.erb +++ b/app/views/stories/suggest.html.erb @@ -3,7 +3,7 @@ Suggest Story Changes - <%= form_for @story, :url => story_suggest_path(@story.short_id), + <%= form_with model: @story, :url => story_suggest_path(@story.short_id), :method => :post, :html => { :id => "edit_story" } do |f| %> <%= render :partial => "stories/form", :locals => { :story => @story, :f => f, :suggesting => true } %> @@ -12,7 +12,7 @@
- <%= submit_tag "Suggest Changes" %> + <%= f.submit "Suggest Changes" %>  or cancel
diff --git a/app/views/tags/_form.html.erb b/app/views/tags/_form.html.erb index 4f567935..53f6a50f 100644 --- a/app/views/tags/_form.html.erb +++ b/app/views/tags/_form.html.erb @@ -1,4 +1,4 @@ -<%= form_for @tag, url: @tag.persisted? ? update_tag_path : tags_path, method: :post do |f| %> +<%= form_with mode: @tag, url: @tag.persisted? ? update_tag_path : tags_path, method: :post do |f| %>
<%= f.label :tag, 'Name:', class: 'required' %> <%= f.text_field :tag %> diff --git a/app/views/users/_invitationform.html.erb b/app/views/users/_invitationform.html.erb index b88e399e..a3fc24ce 100644 --- a/app/views/users/_invitationform.html.erb +++ b/app/views/users/_invitationform.html.erb @@ -5,24 +5,24 @@ if they cause problems. Please use your discretion when inviting persons you don't personally know.

-<%= form_tag invitations_path, :method => :post do |f| %> +<%= form_with url: invitations_path, :method => :post do |f| %> <% if defined?(return_home) && return_home %> - <%= hidden_field_tag :return_home, 1 %> + <%= f.hidden_field :return_home, 1 %> <% end %>
- <%= label_tag :email, "E-mail Address:", :class => "required" %> - <%= email_field_tag :email, "", :size => 30, :autocomplete => "off" %> + <%= f.label :email, "E-mail Address:", :class => "required" %> + <%= f.email_field :email, :size => 30, :autocomplete => "off" %>
- <%= label_tag :memo, "Memo to User:", :class => "required" %> - <%= text_field_tag :memo, "", :size => 60 %> + <%= f.label :memo, "Memo to User:", :class => "required" %> + <%= f.text_field :memo, :size => 60 %>

- <%= submit_tag "Send Invitation" %> + <%= f.submit "Send Invitation" %>
<% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 0f140e13..d5d67e0a 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -169,14 +169,14 @@ <%= render partial: 'mod_notes/table', locals: { mod_notes: ModNote.for(@showing_user).limit(10), } %> - <%= form_for @mod_note, method: :post do |f| %> + <%= form_with model: @mod_note, method: :post do |f| %> <%= error_messages_for @mod_note %> <%= f.hidden_field :username %>
<%= f.label :note, "New Note:", :class => "required" %> <%= f.text_area :note, :style => "width: 500px;", :rows => 5 %>
-

<%= submit_tag "ModNote" %>
+

<%= f.submit "ModNote" %>
<% end %> @@ -214,13 +214,13 @@ <% if @showing_user.is_banned? || @showing_user.banned_from_inviting? %> - <%= form_tag user_unban_path, :method => :post do %> + <%= form_with url: user_unban_path, :method => :post do |f| %>

<% if @showing_user.is_banned? %> - <%= submit_tag "Unban" %> + <%= f.submit "Unban" %> <% end %> <% if @showing_user.banned_from_inviting? %> - <%= submit_tag "Enable Invites", formaction: user_enable_invite_path %> + <%= f.submit "Enable Invites", formaction: user_enable_invite_path %> <% end %>

<% end %> @@ -231,17 +231,17 @@ Banning or disabling invites for a user will send an e-mail to the user with the reason below, with your e-mail address as the Reply-To so the user can respond.

- <%= form_tag user_ban_path, :method => :post do %> + <%= form_with url: user_ban_path, :method => :post do |f| %>
- <%= label_tag :reason, "Reason:", :class => "required" %> - <%= text_field_tag :reason, "", :size => 40 %> + <%= f.label :reason, "Reason:", :class => "required" %> + <%= f.text_field :reason, :size => 40 %>

<% if !@showing_user.is_banned? %> - <%= submit_tag "Ban", class: 'deletion' %> + <%= f.submit "Ban", class: 'deletion' %> <% end %> <% if !@showing_user.banned_from_inviting? %> - <%= submit_tag "Disable Invites", formaction: user_disable_invite_path %> + <%= f.submit "Disable Invites", formaction: user_disable_invite_path %> <% end %>

<% end %> diff --git a/extras/prohibit_form_for_and_form_tag.rb b/extras/prohibit_form_for_and_form_tag.rb new file mode 100644 index 00000000..52fe6514 --- /dev/null +++ b/extras/prohibit_form_for_and_form_tag.rb @@ -0,0 +1,23 @@ +module RuboCop + module Cop + module Style + class DisallowFormForandFormTag < Cop + MSG = 'Use `.form_with` and remove the `.form_tag` and `.form_for`'.freeze + + def_node_matcher :form_for_exists?, <<-PATTERN + (send _ :form_for ...) + PATTERN + + def_node_matcher :form_tag_exists?, <<-PATTERN + (send _ :form_tag ...) + PATTERN + + def on_send(node) + return unless form_for_exists?(node) || form_tag_exists?(node) + + add_offense(node) + end + end + end + end +end