我已经移动了我的应用程序以利用Active Record会话存储,并注意到现在当有人未正确填写表单时,他们将被重定向而没有任何Flash通知。仔细观察,似乎它们被重定向了两次,并且闪存丢失了。
class PotentialClient < ApplicationRecord
belongs_to :location
validates_presence_of :first_name, :last_name, :email, :phone, :referrer, :location_id
validates_uniqueness_of :email, :phone, case_sensitive: false, scope: :location_id
end
def create
@potential_client = PotentialClient.new(potential_client_params)
@potential_client.name = @potential_client[:first_name] + " " + @potential_client[:last_name]
unless ValidatesEmailFormatOf::validate_email_format(@potential_client.email).nil?
unless @potential_client.email.blank?
@potential_client.email = "invalid_email_" + Random.new.rand(99999999999).to_s + "@fake_email.com"
end
end
respond_to do |format|
# Successful Submission
if @potential_client.save
session[:potential_client] = nil
session[:name] = "#{ @potential_client.first_name.titleize }"
PotentialClientsMailer.new_lead_email(@potential_client).deliver_later
session[:sent_from] = "potential_client"
session[:location_id] = params[:location_id]
format.html { redirect_to thank_you_locations_path }
format.js { render :json => @potential_client }
# Unsuccessful submission
else
format.html {
p "ERROR", @potential_client
flash[:alert] = @potential_client.errors.full_messages
session[:errors] = @potential_client.errors.full_messages
session[:potential_client] = @potential_client || {}
redirect_to Location.friendly.find(@potential_client.location_id)
}
format.js {
render json: @potential_client.errors, status: :unprocessable_entity
}
end
end
我一直看到错误:
TypeError (can't dump hash with default proc):
通过删除自定义验证器可以缓解这种情况,但是当我查看日志时仍然不知道发生了什么
app/controllers/potential_clients_controller.rb:35
Location Load (68.4ms) SELECT "locations".* FROM "locations" WHERE "locations"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
↳ app/controllers/potential_clients_controller.rb:35
PotentialClient Exists (81.7ms) SELECT 1 AS one FROM "potential_clients" WHERE LOWER("potential_clients"."email") = LOWER($1) AND "potential_clients"."location_id" = $2 LIMIT $3 [["email", ""], ["location_id", "1"], ["LIMIT", 1]]
↳ app/controllers/potential_clients_controller.rb:35
PotentialClient Exists (70.1ms) SELECT 1 AS one FROM "potential_clients" WHERE LOWER("potential_clients"."phone") = LOWER($1) AND "potential_clients"."location_id" = $2 LIMIT $3 [["phone", ""], ["location_id", "1"], ["LIMIT", 1]]
↳ app/controllers/potential_clients_controller.rb:35
(65.7ms) ROLLBACK
↳ app/controllers/potential_clients_controller.rb:35
"ERROR"
#<PotentialClient id: nil, created_at: nil, updated_at: nil, name: " ", email: "", phone: "", message: "", time_preference: nil, contact_method: nil, location_id: "1", sign_up_form: nil, referrer: "", mindbody_id: nil, signed: nil, had_consultation: false, first_name: "", last_name: "">
{:first_name=>["can't be blank"], :last_name=>["can't be blank"], :email=>["can't be blank"], :phone=>["can't be blank"], :referrer=>["can't be blank"]}
Location Load (64.2ms) SELECT "locations".* FROM "locations" WHERE "locations"."slug" = $1 ORDER BY "locations"."id" ASC LIMIT $2 [["slug", "1"], ["LIMIT", 1]]
↳ app/controllers/potential_clients_controller.rb:60
Location Load (65.3ms) SELECT "locations".* FROM "locations" WHERE "locations"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
↳ app/controllers/potential_clients_controller.rb:60
CACHE Location Load (0.0ms) SELECT "locations".* FROM "locations" WHERE "locations"."slug" = $1 ORDER BY "locations"."id" ASC LIMIT $2 [["slug", "1"], ["LIMIT", 1]]
↳ app/controllers/potential_clients_controller.rb:61
CACHE Location Load (0.0ms) SELECT "locations".* FROM "locations" WHERE "locations"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
↳ app/controllers/potential_clients_controller.rb:61
Redirected to http://localhost:3001/locations/newton
Completed 302 Found in 812ms (ActiveRecord: 771.8ms)
(65.5ms) BEGIN
↳ /Users/jeremylopez/.rvm/gems/ruby-2.3.4/gems/activerecord-5.2.0/lib/active_record/log_subscriber.rb:98
ActiveRecord::SessionStore::Session Update (68.4ms) UPDATE "sessions" SET "data" = $1, "updated_at" = $2 WHERE "sessions"."id" = $3 [["data", "BAh7CEkiC2Vycm9ycwY6BkVGWwpJIh5GaXJzdCBuYW1lIGNhbid0IGJlIGJs\nYW5rBjs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bmsGOwBUOg5sYXN0X25hbWVbBkkiE2Nhbid0IGJlIGJsYW5rBjsAVDoKZW1h\naWxbBkkiE2Nhbid0IGJlIGJsYW5rBjsAVDoKcGhvbmVbBkkiE2Nhbid0IGJl\nIGJsYW5rBjsAVDoNcmVmZXJyZXJbBkkiE2Nhbid0IGJlIGJsYW5rBjsAVHsK\nO3hbBnsGOgplcnJvcjoKYmxhbms7eVsGewY7fTt+O3pbBnsGO307fjt7WwZ7\nBjt9O347fFsGewY7fTt+SSIKZmxhc2gGOwBUewdJIgxkaXNjYXJkBjsAVFsA\nSSIMZmxhc2hlcwY7AFR7BkkiCmFsZXJ0BjsARkkiFUVld2Z3ZWZ3ZWZ3ZWZ3\nZWYGOwBU\n"], ["updated_at", "2018-09-06 16:27:34.500489"], ["id", 670956]]
↳ /Users/jeremylopez/.rvm/gems/ruby-2.3.4/gems/activerecord-5.2.0/lib/active_record/log_subscriber.rb:98
(67.3ms) COMMIT
↳ /Users/jeremylopez/.rvm/gems/ruby-2.3.4/gems/activerecord-5.2.0/lib/active_record/log_subscriber.rb:98
Started GET "/locations/newton" for ::1 at 2018-09-06 12:27:34 -0400
Processing by LocationsController#show as HTML
知道发生了什么吗?我不确定是由于会话存储还是其他原因?