Skip to content
This repository has been archived by the owner on Feb 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #108 from MyDry/fix/validation-error-message-flash
Browse files Browse the repository at this point in the history
Revert "Refactor inform_validation_errors helper function"
  • Loading branch information
tanacchi authored Oct 12, 2018
2 parents 5438e1e + 65f4955 commit e203441
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def edit
end

def update
if @user.update(user_params)
if @user.update_attributes(user_params)
flash[:success] = "更新しました"
redirect_to @user
else
Expand Down
14 changes: 7 additions & 7 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ def format_datetime(datetime, type = :datetime)
datetime.strftime(format)
end

def inform_validation_errors(obj)
content_tag(:p) do
obj.errors.full_messages.each do |message|
concat content_tag(:div, class: 'alert alert-danger') do
concat content_tag(:a, 'x', data: { dismiss: 'alert' })
message
end
def inform_validation_errror(obj)
html_text = ''
obj.errors.full_messages.each do |message|
html_text += content_tag(:div, class: 'alert alert-danger') do
content_tag(:a, 'x', data: { dismiss: 'alert' })
message
end
end
raw(html_text)
end
end
5 changes: 3 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class User < ApplicationRecord
#validates :email, {presence: true, uniqueness: true}
validates :password,
confirmation: true,
presence: { message: 'を入力してください'}

presence: { message: 'を入力してください'},
allow_nil: true

has_many :ideas, dependent: :destroy
has_many :topics, dependent: :destroy
has_many :likes, dependent: :destroy
Expand Down
4 changes: 3 additions & 1 deletion app/views/ideas/_form_field.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<%= inform_validation_errors(idea) %>
<p>
<%= inform_validation_errror(idea) %>
</p>
<div class="container">
<div class="form-group col-xs-4">
<%= form_for(idea, url: next_path) do |f| %>
Expand Down
4 changes: 3 additions & 1 deletion app/views/topics/_form_field.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<%= inform_validation_errors(topic) %>
<p>
<%= inform_validation_errror(topic) %>
</p>
<div class="container">
<div class="form-group col-xs-4">
<%= form_for(topic) do |f| %>
Expand Down
4 changes: 3 additions & 1 deletion app/views/users/_form_field.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<%= inform_validation_errors(user) %>
<p>
<%= inform_validation_errror(user) %>
</p>
<div class="container">
<div class="form-group col-xs-4">
<%= form_for(user) do |f| %>
Expand Down
2 changes: 2 additions & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ ja:
email: メールアドレス
password: パスワード
password_confirmation: パスワード(確認用)
title: タイトル
body: 本文

0 comments on commit e203441

Please sign in to comment.