Skip to content

Commit deb1840

Browse files
authored
Better View Customisation (#17)
1 parent b9de4a1 commit deb1840

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ See some :camera: [examples here](support/images/examples/).
8787

8888
> ℹ️ If you are using your own layout, don't forget to render the flash messages in that layout. You can do something [like this](app/views/sudo_rails/_flash_alert.html.erb).
8989
90+
You can also override the view by calling the `sudo_rails:view` generator. This will create a copy of the view file at `app/views/sudo_rails/confirm_form.html.erb` which can be later modified as per your requirements.
91+
9092
### Confirmation strategy
9193

9294
You should define how to validate the password using the `confirm_strategy` option. It must be a `lambda`, which will receive 2 arguments: the controller instance (`context`) and the password from the user.

app/views/sudo_rails/confirm_form.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</div>
88

99
<div class='sudo-form'>
10-
<%= form_tag '/sudo_rails/confirm' do |f| %>
10+
<%= form_tag sudo_rails_confirm_path do |f| %>
1111
<%= hidden_field_tag :locale, I18n.locale %>
1212
<%= hidden_field_tag :target_path, params[:target_path] || request.url %>
1313
<%= password_field_tag :password, nil, required: true, placeholder: t('sudo_rails.password') %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class SudoRails::ViewGenerator < Rails::Generators::Base
2+
source_root File.expand_path("../../../app/views/sudo_rails/", __dir__)
3+
4+
def copy_initializer_file
5+
copy_file "confirm_form.html.erb", "app/views/sudo_rails/confirm_form.html.erb"
6+
end
7+
end

lib/sudo_rails/engine.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ class Engine < ::Rails::Engine
33
isolate_namespace SudoRails
44

55
initializer "sudo_rails.controller_ext" do
6-
ActiveSupport.on_load(:action_controller) do
6+
ActiveSupport.on_load(:action_controller_base) do
77
include SudoRails::ControllerExt
88
end
99
end
1010

1111
initializer 'sudo_rails.routes' do |app|
1212
app.routes.append do
13-
post '/sudo_rails/confirm' => 'sudo_rails/application#confirm'
13+
post '/sudo_rails/confirm' => 'sudo_rails/application#confirm', as: :sudo_rails_confirm
1414
end
1515
end
1616
end

spec/dummy/config/environments/development.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
config.active_support.deprecation = :log
3838

3939
# Raise an error on page load if there are pending migrations.
40-
config.active_record.migration_error = :page_load
40+
# config.active_record.migration_error = :page_load
4141

4242
# Highlight code that triggered database queries in logs.
43-
config.active_record.verbose_query_logs = true
43+
# config.active_record.verbose_query_logs = true
4444

4545
# Debug mode disables concatenation and preprocessing of assets.
4646
# This option may cause significant delays in view rendering with a large

0 commit comments

Comments
 (0)