Skip to content

Commit

Permalink
Use form_with, require email format in example, handle Rails 7 (turbo…
Browse files Browse the repository at this point in the history
…) form redirect (#128)
  • Loading branch information
yshmarov committed Nov 30, 2022
1 parent ebe54e6 commit 029d24e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

### Changed

- Replaced `form_for` with `form_with` in view template ([#128](https://github.com/mikker/passwordless/pull/128))
- Added frontend validation for email presence in views ([#128](https://github.com/mikker/passwordless/pull/128))

### Fixed

- Fix `Passwordless#ControllerHelpers` to be used outside controllers (#124)
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ Then specify which field on your `User` record is the email field with:

```ruby
class User < ApplicationRecord
validates :email, presence: true, uniqueness: { case_sensitive: false }
validates :email,
presence: true,
uniqueness: { case_sensitive: false },
format: { with: URI::MailTo::EMAIL_REGEXP }

passwordless_with :email # <-- here!
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/passwordless/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= form_for @session, url: send(Passwordless.mounted_as).sign_in_path do |f| %>
<%= form_with model: @session, url: send(Passwordless.mounted_as).sign_in_path, data: { turbo: 'false' } do |f| %>
<% email_field_name = :"passwordless[#{@email_field}]" %>
<%= text_field_tag email_field_name, params.fetch(email_field_name, nil) %>
<%= text_field_tag email_field_name, params.fetch(email_field_name, nil), required: true %>
<%= f.submit I18n.t('passwordless.sessions.new.submit') %>
<% end %>
2 changes: 1 addition & 1 deletion test/dummy/app/views/registrations/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_for @user, url: registrations_path do |f| %>
<%= form_with model: @user, url: registrations_path do |f| %>
<%= f.label :email %>
<%= f.email_field :email %>
<%= f.submit %>
Expand Down

0 comments on commit 029d24e

Please sign in to comment.