I'm trying to attach a js file to a model and store in s3 but every time I run the attach method with file io objects, the server gets hung up in a recursive create and delete of the activestorage attachment database as you can see in these server logs:
ActiveStorage::Blob Create (0.5ms) INSERT INTO "active_storage_blobs" ("key", "filename", "content_type", "metadata", "service_name", "byte_size", "checksum", "created_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id" [["key", "p7bq76rurim77iao2r9a01pj0pwg"], ["filename", "c520252d-a889-4636-ad9c-30973429e25c.js"], ["content_type", "application/javascript"], ["metadata", "{\"identified\":true}"], ["service_name", "amazon"], ["byte_size", 13], ["checksum", "XY+qICmXk3H4sx9RJIwiMA=="], ["created_at", "2022-08-30 21:06:54.911872"]]
↳ app/models/property.rb:22:in `make_js_file'
ActiveStorage::Attachment Create (0.5ms) INSERT INTO "active_storage_attachments" ("name", "record_type", "record_id", "blob_id", "created_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["name", "js_file"], ["record_type", "Property"], ["record_id", "c520252d-a889-4636-ad9c-30973429e25c"], ["blob_id", "e96f2305-a7dd-4e81-b4be-95e8c8d00df5"], ["created_at", "2022-08-30 21:06:54.917626"]]
↳ app/models/property.rb:22:in `make_js_file'
ActiveStorage::Attachment Destroy (0.5ms) DELETE FROM "active_storage_attachments" WHERE "active_storage_attachments"."id" = $1 [["id", "b705726b-b97d-47d6-bb70-de0c9d4dfa6b"]]
↳ app/models/property.rb:22:in `make_js_file'
ActiveStorage::Blob Create (0.3ms) INSERT INTO "active_storage_blobs" ("key", "filename", "content_type", "metadata", "service_name", "byte_size", "checksum", "created_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id" [["key", "zybcvyig2o0u7dgogisklfnig7xv"], ["filename", "c520252d-a889-4636-ad9c-30973429e25c.js"], ["content_type", "application/javascript"], ["metadata", "{\"identified\":true}"], ["service_name", "amazon"], ["byte_size", 13], ["checksum", "XY+qICmXk3H4sx9RJIwiMA=="], ["created_at", "2022-08-30 21:06:54.944469"]]
↳ app/models/property.rb:22:in `make_js_file'
ActiveStorage::Attachment Create (0.3ms) INSERT INTO "active_storage_attachments" ("name", "record_type", "record_id", "blob_id", "created_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["name", "js_file"], ["record_type", "Property"], ["record_id", "c520252d-a889-4636-ad9c-30973429e25c"], ["blob_id", "23e176a4-3816-47fe-97a5-e2bb3af97a1d"], ["created_at", "2022-08-30 21:06:54.947629"]]
↳ app/models/property.rb:22:in `make_js_file'
ActiveStorage::Attachment Destroy (0.3ms) DELETE FROM "active_storage_attachments" WHERE "active_storage_attachments"."id" = $1 [["id", "7d0e1765-4d6a-46ed-8b29-012adecda684"]]
↳ app/models/property.rb:22:in `make_js_file'
ActiveStorage::Blob Create (0.4ms) INSERT INTO "active_storage_blobs" ("key", "filename", "content_type", "metadata", "service_name", "byte_size", "checksum", "created_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id" [["key", "8997y96c81r8fxcofbe854ivu2r1"], ["filename", "c520252d-a889-4636-ad9c-30973429e25c.js"], ["content_type", "application/javascript"], ["metadata", "{\"identified\":true}"], ["service_name", "amazon"], ["byte_size", 13], ["checksum", "XY+qICmXk3H4sx9RJIwiMA=="], ["created_at", "2022-08-30 21:06:54.965508"]]
↳ app/models/property.rb:22:in `make_js_file'
ActiveStorage::Attachment Create (0.4ms) INSERT INTO "active_storage_attachments" ("name", "record_type", "record_id", "blob_id", "created_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["name", "js_file"], ["record_type", "Property"], ["record_id", "c520252d-a889-4636-ad9c-30973429e25c"], ["blob_id", "4646e337-2ae3-4afc-aab0-48f84af4657d"], ["created_at", "2022-08-30 21:06:54.969796"]]
↳ app/models/property.rb:22:in `make_js_file'
ActiveStorage::Attachment Destroy (2.2ms) DELETE FROM "active_storage_attachments" WHERE "active_storage_attachments"."id" = $1 [["id", "c687a1fa-7ba3-4e76-af20-a3867c153b95"]]
↳ app/models/property.rb:22:in `make_js_file'
ActiveStorage::Blob Create (0.5ms) INSERT INTO "active_storage_blobs" ("key", "filename", "content_type", "metadata", "service_name", "byte_size", "checksum", "created_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id" [["key", "83hcoeo5mdwo4glg3gjmb7jx2l34"], ["filename", "c520252d-a889-4636-ad9c-30973429e25c.js"], ["content_type", "application/javascript"], ["metadata", "{\"identified\":true}"], ["service_name", "amazon"], ["byte_size", 13], ["checksum", "XY+qICmXk3H4sx9RJIwiMA=="], ["created_at", "2022-08-30 21:06:54.998981"]]
↳ app/models/property.rb:22:in `make_js_file'
ActiveStorage::Attachment Create (0.5ms) INSERT INTO "active_storage_attachments" ("name", "record_type", "record_id", "blob_id", "created_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["name", "js_file"], ["record_type", "Property"], ["record_id", "c520252d-a889-4636-ad9c-30973429e25c"], ["blob_id", "9e053cf2-a248-44b9-bf37-b3005efea1be"], ["created_at", "2022-08-30 21:06:55.004691"]]
↳ app/models/property.rb:22:in `make_js_file'
ActiveStorage::Attachment Destroy (0.3ms) DELETE FROM "active_storage_attachments" WHERE "active_storage_attachments"."id" = $1 [["id", "5bc44cce-62cf-4dc5-829e-97dfd9b28411"]]
↳ app/models/property.rb:22:in `make_js_file'
ActiveStorage::Blob Create (0.4ms) INSERT INTO "active_storage_blobs" ("key", "filename", "content_type", "metadata", "service_name", "byte_size", "checksum", "created_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id" [["key", "a4c22dupjyndviedp41r6e8cg7dx"], ["filename", "c520252d-a889-4636-ad9c-30973429e25c.js"], ["content_type", "application/javascript"], ["metadata", "{\"identified\":true}"], ["service_name", "amazon"], ["byte_size", 13], ["checksum", "XY+qICmXk3H4sx9RJIwiMA=="], ["created_at", "2022-08-30 21:06:55.029049"]]
↳ app/models/property.rb:22:in `make_js_file'
I thought maybe where I run the attach method might affect it so I tried adding it in the model, controller, and tested in the console and I get the same result.
I also tried using File, Temfile, and StringIO but get the same result.
Here is an example
dir = Rails.root.join("tmp/files")
file = File.open("#{dir}/#{self.id}.js", "w") { |f| f.write "function(){};" }
self.js_file.attach(
io: File.open("#{dir}/#{self.id}.js"),
filename: "#{self.id}.js",
content_type: 'application/javascript'
)
Not sure what the problem might be.
I made a mistake. It seems like adding it in the model with a callback created a recursive loop when the attach method is applied to the model. Better to leave out of the model
Related
I integrated comfortable-mexican-sofa CMS with my rails 6.0 app. Everything working fine. But file upload functionality is not working.
The server is continuously running creating and deleting ActiveStorage::Blob and ActiveStorage::Attachment
ActiveStorage::Blob Create (0.8ms) INSERT INTO "active_storage_blobs" ("key", "filename", "content_type", "metadata", "byte_size", "checksum", "created_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["key", "56qutde9f90cknxanwuqnivgv2eo"], ["filename", "g500-black-back.jpg"], ["content_type", "image/jpeg"], ["metadata", "{\"identified\":true}"], ["byte_size", 2223], ["checksum", "EyM+/P6Ccq9Pw69YV7fAww=="], ["created_at", "2019-09-30 11:26:38.992295"]]
ActiveStorage::Attachment Create (2.6ms) INSERT INTO "active_storage_attachments" ("name", "record_type", "record_id", "blob_id", "created_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["name", "attachment"], ["record_type", "Comfy::Cms::File"], ["record_id", 6], ["blob_id", 356], ["created_at", "2019-09-30 11:26:39.029294"]]
(0.4ms) SELECT "comfy_cms_categories"."id" FROM "comfy_cms_categories" WHERE "comfy_cms_categories"."categorized_type" = $1 [["categorized_type", "Comfy::Cms::File"]]
Comfy::Cms::Categorization Load (0.4ms) SELECT "comfy_cms_categorizations".* FROM "comfy_cms_categorizations" WHERE "comfy_cms_categorizations"."categorized_id" = $1 AND "comfy_cms_categorizations"."categorized_type" = $2 AND "comfy_cms_categorizations"."category_id" = $3 [["categorized_id", 6], ["categorized_type", "Comfy::Cms::File"], ["category_id", 1]]
ActiveStorage::Attachment Destroy (0.7ms) DELETE FROM "active_storage_attachments" WHERE "active_storage_attachments"."id" = $1 [["id", 355]]
ActiveStorage::Blob Create (0.7ms) INSERT INTO "active_storage_blobs" ("key", "filename", "content_type", "metadata", "byte_size", "checksum", "created_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["key", "so1r6i8qli6p5etiz1fz1jee4hcy"], ["filename", "g500-black-back.jpg"], ["content_type", "image/jpeg"], ["metadata", "{\"identified\":true}"], ["byte_size", 2223], ["checksum", "EyM+/P6Ccq9Pw69YV7fAww=="], ["created_at", "2019-09-30 11:26:39.113055"]]
ActiveStorage::Attachment Create (0.9ms) INSERT INTO "active_storage_attachments" ("name", "record_type", "record_id", "blob_id", "created_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["name", "attachment"], ["record_type", "Comfy::Cms::File"], ["record_id", 6], ["blob_id", 357], ["created_at", "2019-09-30 11:26:39.130977"]]
(0.4ms) SELECT "comfy_cms_categories"."id" FROM "comfy_cms_categories" WHERE "comfy_cms_categories"."categorized_type" = $1 [["categorized_type", "Comfy::Cms::File"]]
Comfy::Cms::Categorization Load (0.4ms) SELECT "comfy_cms_categorizations".* FROM "comfy_cms_categorizations" WHERE "comfy_cms_categorizations"."categorized_id" = $1 AND "comfy_cms_categorizations"."categorized_type" = $2 AND "comfy_cms_categorizations"."category_id" = $3 [["categorized_id", 6], ["categorized_type", "Comfy::Cms::File"], ["category_id", 1]]
ActiveStorage::Attachment Destroy (0.7ms) DELETE FROM "active_storage_attachments" WHERE "active_storage_attachments"."id" = $1 [["id", 356]]
I have a request that makes several changes to the same record, however I only need to store a version when one of the attributes changes from false to true. I tried the following:
has_paper_trail on: [:update],
only: {
redone: Proc.new { |srv|
srv.redone == true && srv.redone_was == false
},
}
But I am still getting versions on changes that do not involve the redone attribute changing from false to true... This is an excerpt from the log:
(0.7ms) BEGIN
SQL (11.3ms) UPDATE "servicings" SET "redone" = $1, "redo_reason" = $2, "updated_at" = $3 WHERE "servicings"."id" = $4 [["redone", false], ["redo_reason", nil], ["updated_at", 2018-07-19 22:46:15 UTC], ["id", 218762]]
SQL (9.7ms) INSERT INTO "versions" ("item_type", "item_id", "event", "object", "object_changes", "created_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["item_type", "Servicing"], ["item_id", 218762], ["event", "update"], ["object", "---\nid: 218762\nwork_order_id: 7462\narea_id: 16563\nhigh_priority: false\ncompleted_at: \ncreated_at: 2018-07-10 19:45:36.245612000 Z\nupdated_at: 2018-07-19 22:14:11.143007000 Z\nassignee_id: 90\nclaimed_by_id: \ncompleted_by_id: 90\noccupied_at: \ndeleted_at: \nstatus: open\napproval_status: \nredone: true\nunable_reason: \nredo_reason: testing paper_trail\napproving_user_id: \napproving_user_name: \napproved_at: \n"], ["object_changes", "---\nredone:\n- true\n- false\nredo_reason:\n- testing paper_trail\n- \nupdated_at:\n- 2018-07-19 22:14:11.143007000 Z\n- 2018-07-19 22:46:15.680447100 Z\n"], ["created_at", 2018-07-19 22:46:15 UTC]]
(5.6ms) COMMIT
(2.0ms) BEGIN
(0.8ms) COMMIT
(1.5ms) BEGIN
SQL (9.1ms) UPDATE "servicings" SET "updated_at" = $1, "status" = $2 WHERE "servicings"."id" = $3 [["updated_at", 2018-07-19 22:46:15 UTC], ["status", "completed"], ["id", 218762]]
SQL (2.8ms) INSERT INTO "versions" ("item_type", "item_id", "event", "object", "object_changes", "created_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["item_type", "Servicing"], ["item_id", 218762], ["event", "update"], ["object", "---\nid: 218762\nredone: false\nredo_reason: \nwork_order_id: 7462\narea_id: 16563\nhigh_priority: false\ncompleted_at: \ncreated_at: 2018-07-10 19:45:36.245612000 Z\nupdated_at: 2018-07-19 22:46:15.680447100 Z\nassignee_id: 90\nclaimed_by_id: \ncompleted_by_id: 90\noccupied_at: \ndeleted_at: \nstatus: open\napproval_status: \nunable_reason: \napproving_user_id: \napproving_user_name: \napproved_at: \n"], ["object_changes", "---\nupdated_at:\n- 2018-07-19 22:46:15.680447100 Z\n- 2018-07-19 22:46:15.981721300 Z\nstatus:\n- open\n- completed\n"], ["created_at", 2018-07-19 22:46:15 UTC]]
(8.7ms) COMMIT
WorkOrder Load (15.1ms) SELECT "work_orders".* FROM "work_orders" WHERE "work_orders"."deleted_at" IS NULL AND "work_orders"."id" = $1 LIMIT $2 [["id", 7462], ["LIMIT", 1]]
(1.2ms) BEGIN
SQL (16.3ms) UPDATE "servicings" SET "completed_at" = $1, "updated_at" = $2 WHERE "servicings"."id" = $3 [["completed_at", 2018-07-19 22:46:16 UTC], ["updated_at", 2018-07-19 22:46:16 UTC], ["id", 218762]]
SQL (7.5ms) INSERT INTO "versions" ("item_type", "item_id", "event", "object", "object_changes", "created_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["item_type", "Servicing"], ["item_id", 218762], ["event", "update"], ["object", "---\nid: 218762\nredone: false\nredo_reason: \nwork_order_id: 7462\narea_id: 16563\nhigh_priority: false\ncompleted_at: \ncreated_at: 2018-07-10 19:45:36.245612000 Z\nupdated_at: 2018-07-19 22:46:15.981721300 Z\nassignee_id: 90\nclaimed_by_id: \ncompleted_by_id: 90\noccupied_at: \ndeleted_at: \nstatus: completed\napproval_status: \nunable_reason: \napproving_user_id: \napproving_user_name: \napproved_at: \n"], ["object_changes", "---\ncompleted_at:\n- \n- 2018-07-19 22:46:16.111954100 Z\nupdated_at:\n- 2018-07-19 22:46:15.981721300 Z\n- 2018-07-19 22:46:16.150183500 Z\n"], ["created_at", 2018-07-19 22:46:16 UTC]]
(2.7ms) COMMIT
What could I be doing wrong?
It's probably because PaperTrail's callback executes after the update. If that's the case, redone_was will always be equal to the current redone value.
You should store your redone_was value somewhere before updating.
class Klass
attr_accessor :old_redone_value
before_save :store_old_redone_value
has_paper_trail on: [:update],
only: {
redone: Proc.new { |srv|
srv.redone == true && srv.old_redone_value == false
},
}
def store_old_redone_value
self.old_redone_value = redone_was
end
end
That's the idea. It's not the best solution, and might not work -- but, it'll lead you somewhere.
<%= f.time_select :exact, {ampm: true, :discard_minute=> true} %> # t.time "exact"
How do I pass the above in params?
session[:challenge_exact] = params[:exact].parse_time_select! # got nil error
session[:challenge_exact] = challenge_params[:exact]
session[:challenge_exact] = [params["challenge"]["exact(1i)"], params["challenge"]["exact(2i)"], params["challenge"]["exact(3i)"], params["challenge"]["exact(4i)"], params["challenge"]["exact(5i)"]].join(',')
None of the above work. After the challenge is created I see that exact: nil even though it was populated in the form.
Started POST "/challenges" for ::1 at 2017-05-02 08:28:31 -0400
Processing by ChallengesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"oN+DzJK+/GGmpTOOVYMUJQdywuENwxhmX/EVeW6NSZ3w1MctoMd/VHS39d+JasEjHujO88nLPSB2qUKEhet5yA==", "challenge"=>{"name"=>"Write 3 Gratitudes", "categorization"=>"health", "category"=>"goal", "deadline(2i)"=>"6", "deadline(3i)"=>"2", "deadline(1i)"=>"2017", "push"=>"0", "message"=>"1", "mail"=>"0", "remind"=>["mon", "thu", ""], "exact(1i)"=>"2017", "exact(2i)"=>"5", "exact(3i)"=>"2", "exact(4i)"=>"08", "exact(5i)"=>"27", "conceal"=>"0"}, "number"=>"", "email"=>"", "button"=>""}
Redirected to http://localhost:3000/signup
Completed 302 Found in 47ms (ActiveRecord: 0.0ms)
After POST challenge a person then creates a user account...
Started POST "/users" for ::1 at 2017-05-03 01:02:13 -0400
Processing by UsersController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"4Lv5NSfH9tMnC9+t5bVC5x1d571y0jhwsgvYU3t2sp85XAnNOsHk+FCmtGcj2wJVysV6IlAIzF4jCx1hIofwsNg==", "user"=>{"name"=>"test", "last_name"=>"daddy", "email"=>"testdaddy#gmail.com", "password"=>"[FILTERED]", "time_zone"=>"Eastern Time (US & Canada)", "subscribe"=>"0"}, "button"=>""}
(0.2ms) BEGIN
User Exists (0.5ms) SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('testdaddy#gmail.com') LIMIT 1
SQL (2.3ms) INSERT INTO "users" ("time_zone", "name", "last_name", "subscribe", "email", "password_digest", "number", "created_at", "updated_at", "activation_digest", "activated") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING "id" [["time_zone", "Eastern Time (US & Canada)"], ["name", "test"], ["last_name", "daddy"], ["subscribe", "f"], ["email", "testdaddy#gmail.com"], ["password_digest", "$2a$10$JSSPUl0JDnUXybnAuSnEO.q5DgZscaU3hRpcM4C5L0a0aEtflzb7ne"], ["number", "15169499507"], ["created_at", "2017-05-03 05:02:14.144232"], ["updated_at", "2017-05-03 05:02:14.144232"], ["activation_digest", "$2a$10$NDtWKvxuJm/Hb9YIOzuVIuPpttCZwjsgYws6HhEcbHc.PukxXNpeLa"], ["activated", "t"]]
(18.8ms) COMMIT
(0.2ms) BEGIN
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 16]]
# AS YOU CAN SEE WITH INSERT INTO CHALLENGES FOR SOME REASON THE SESSION PARAMS FOR EXACT ISN'T PASSING FOR EXACT
SQL (0.6ms) INSERT INTO "challenges" ("committed", "name", "categorization", "category", "deadline", "remind", "message", "user_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "id" [["committed", nil], ["name", "Write 3 Gratitudes"], ["categorization", "health"], ["category", "goal"], ["deadline", "2017-06-03"], ["remind", "---\n- mon\n- thu\n- ''\n"], ["message", "t"], ["user_id", 16], ["created_at", "2017-05-03 05:02:14.434251"], ["updated_at", "2017-05-03 05:02:14.434251"]]
ActsAsTaggableOn::Tag Load (0.6ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL) [["taggable_id", 40], ["taggable_type", "Challenge"]]
ActsAsTaggableOn::Tag Load (0.8ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 AND (taggings.context = 'tags' AND
taggings.tagger_id = 16 AND
taggings.tagger_type = 'User') [["taggable_id", 40], ["taggable_type", "Challenge"]]
(17.2ms) COMMIT
Redirected to http://localhost:3000/
How it appears in console...
exact: 2000-01-01 02:32:00 UTC>
You can access exact params like:
> params[:challenge]["exact(1i)"]
#=> "2017"
> params[:challenge]["exact(2i)"]
#=> "5"
> params[:challenge]["exact(3i)"]
#=> "2"
> params[:challenge]["exact(4i)"]
#=> "08"
> params[:challenge]["exact(5i)"]
#=> "27"
You can parse time like this:
exact_time = "#{params[:challenge]['exact(4i)']}:#{params[:challenge]['exact(5i)']}"
#=> "08:27"
> session[:challenge_exact] = Time.parse(exact_time)
#=> 2017-05-03 08:27:00 +0530
I would do:
session[:challenge_exact] = components_to_absolute(params[:exact])
def components_to_absolute(components)
DateTime.new(components['exact(1i)'].to_i,
components['exact(2i)'].to_i,
components['exact(3i)'].to_i,
components['exact(4i)'].to_i,
components['exact(5i)'].to_i)
end
I have a customer model with devise authetication:
class Customer < ActiveRecord::Base
devise :database_authenticatable, :registerable, :omniauthable,
:recoverable, :rememberable, :trackable
validates_presence_of :name
validates_uniqueness_of :nickname
has_many :messages
has_many :orders
acts_as_voter
before_save :complete_nickname
def complete_nickname
if !self.nickname?
self.nickname = self.email
end
end
end
I'm testing with rspec, so in spec/factories folder I have customers.rb:
require 'ffaker'
FactoryGirl.define do
factory :customer do
name { FFaker::Name.first_name }
surname { FFaker::Name.last_name }
nickname { FFaker::Internet.user_name }
email { FFaker::Internet.email }
password 'antoniorossi'
password_confirmation 'antoniorossi'
end
end
and in spec/models customer_spec.rb
require 'rails_helper'
require 'ffaker'
RSpec.describe Customer, :type => :model do
it 'has a valid factory' do
expect(build(:customer)).to be_valid
end
it 'has a valid factory with blank field' do
expect(build(:customer, surname: nil)).to be_valid
expect(build(:customer, nickname: nil)).to be_valid
end
before do
FactoryGirl.create(:customer, email: 'taken_mail')
FactoryGirl.create(:customer, nickname: 'taken_nickname')
end
it 'it is invalidy without name' do
expect(FactoryGirl.build(:customer, name: nil)).to_not be_valid
end
it 'it is invalidy without email' do
expect(FactoryGirl.build(:customer, email: nil)).to_not be_valid
end
it 'it is invalidy without password confirmation' do
expect(FactoryGirl.build(:customer, password_confirmation: nil)).to_not be_valid
end
it 'it is invalidy if password and password_confirmation do not match' do
expect(FactoryGirl.build(:customer, password_confirmation: 'antonioross')).to_not be_valid
end
it "it is invalidy with an already used email" do
expect(FactoryGirl.build(:customer, email: 'taken_mail')).to_not be_valid
end
it "it is invalidy with an already used nickname" do
expect(FactoryGirl.build(:customer, nickname: 'taken_nickname')).to_not be_valid
end
end
executing rspec command I have output:
Customer
(1.1ms) BEGIN
(2.2ms) COMMIT
(1.2ms) BEGIN
(0.4ms) SAVEPOINT active_record_1
Customer Exists (1.3ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'ricky_grimes' LIMIT 1
SQL (1.0ms) INSERT INTO "customers" ("name", "surname", "nickname", "email", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["name", "Erika"], ["surname", "Wehner"], ["nickname", "ricky_grimes"], ["email", "taken_mail"], ["encrypted_password", "$2a$04$I69kG7ajhgVy9u4pZdR1xuTrvmjOfW2sX74Y0jJH3gFu9pUKejCli"], ["created_at", "2015-11-27 15:45:18.830500"], ["updated_at", "2015-11-27 15:45:18.830500"]]
(0.3ms) RELEASE SAVEPOINT active_record_1
(0.3ms) SAVEPOINT active_record_1
Customer Exists (0.8ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'taken_nickname' LIMIT 1
SQL (0.7ms) INSERT INTO "customers" ("name", "surname", "nickname", "email", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["name", "Britney"], ["surname", "Conn"], ["nickname", "taken_nickname"], ["email", "savion_rogahn#conroy.ca"], ["encrypted_password", "$2a$04$ZuTw5k2PVQZ2T0z9TrS3G.s7NKGd1uX88gGms96Y7xn03vpu6Ksi2"], ["created_at", "2015-11-27 15:45:18.847077"], ["updated_at", "2015-11-27 15:45:18.847077"]]
(0.4ms) RELEASE SAVEPOINT active_record_1
Customer Exists (0.6ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'georgianna.dickens' LIMIT 1
(0.4ms) ROLLBACK
has a valid factory
(0.3ms) BEGIN
(0.2ms) COMMIT
(0.2ms) BEGIN
(0.3ms) SAVEPOINT active_record_1
Customer Exists (0.8ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'davonte_johnston' LIMIT 1
SQL (1.6ms) INSERT INTO "customers" ("name", "surname", "nickname", "email", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["name", "Johan"], ["surname", "Bashirian"], ["nickname", "davonte_johnston"], ["email", "taken_mail"], ["encrypted_password", "$2a$04$UMEYJWN2mOYTIUoUqkl4TuQtz3GnOwZBPoZDQ3nXXCEJpyfRhIRMO"], ["created_at", "2015-11-27 15:45:18.876060"], ["updated_at", "2015-11-27 15:45:18.876060"]]
(0.4ms) RELEASE SAVEPOINT active_record_1
(0.3ms) SAVEPOINT active_record_1
Customer Exists (0.7ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'taken_nickname' LIMIT 1
SQL (0.6ms) INSERT INTO "customers" ("name", "surname", "nickname", "email", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["name", "Nona"], ["surname", "Kozey"], ["nickname", "taken_nickname"], ["email", "marcel#balistreriflatley.com"], ["encrypted_password", "$2a$04$G9epfoLwQ16QRyx2G5UHC.6P724N9VlGluZLiyn8sS0UYvzb8atjS"], ["created_at", "2015-11-27 15:45:18.892194"], ["updated_at", "2015-11-27 15:45:18.892194"]]
(0.3ms) RELEASE SAVEPOINT active_record_1
Customer Exists (0.6ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'clara_upton' LIMIT 1
Customer Exists (0.8ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" IS NULL LIMIT 1
(0.7ms) ROLLBACK
has a valid factory with blank field
(0.3ms) BEGIN
(0.2ms) COMMIT
(0.2ms) BEGIN
(0.3ms) SAVEPOINT active_record_1
Customer Exists (0.6ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'della.bechtelar' LIMIT 1
SQL (0.6ms) INSERT INTO "customers" ("name", "surname", "nickname", "email", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["name", "Jazmyn"], ["surname", "Keeling"], ["nickname", "della.bechtelar"], ["email", "taken_mail"], ["encrypted_password", "$2a$04$WFKmWHoJY7ao17HxexhsXuXQMavFxegG2RNZz2bh41UmTo1MNvI/m"], ["created_at", "2015-11-27 15:45:18.926027"], ["updated_at", "2015-11-27 15:45:18.926027"]]
(0.3ms) RELEASE SAVEPOINT active_record_1
(0.3ms) SAVEPOINT active_record_1
Customer Exists (0.6ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'taken_nickname' LIMIT 1
SQL (0.7ms) INSERT INTO "customers" ("name", "surname", "nickname", "email", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["name", "Sean"], ["surname", "Casper"], ["nickname", "taken_nickname"], ["email", "ozella.schroeder#von.com"], ["encrypted_password", "$2a$04$f7.az4xueyZxHOMGKNu6ReQJ9sCykNbk2a5/3cb8mwrbxNtf/eSq6"], ["created_at", "2015-11-27 15:45:18.939113"], ["updated_at", "2015-11-27 15:45:18.939113"]]
(0.4ms) RELEASE SAVEPOINT active_record_1
Customer Exists (0.6ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'neil_prosacco' LIMIT 1
(0.3ms) ROLLBACK
it is invalidy without name
(0.2ms) BEGIN
(0.2ms) COMMIT
(0.2ms) BEGIN
(0.3ms) SAVEPOINT active_record_1
Customer Exists (0.7ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'kailyn_carroll' LIMIT 1
SQL (0.6ms) INSERT INTO "customers" ("name", "surname", "nickname", "email", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["name", "Chet"], ["surname", "Heidenreich"], ["nickname", "kailyn_carroll"], ["email", "taken_mail"], ["encrypted_password", "$2a$04$OLVf3jnY.2sjGtMa3qjBOOHRW2WWMqfnNGTLYJvCJVW36oHMJxSjK"], ["created_at", "2015-11-27 15:45:19.009064"], ["updated_at", "2015-11-27 15:45:19.009064"]]
(0.3ms) RELEASE SAVEPOINT active_record_1
(0.3ms) SAVEPOINT active_record_1
Customer Exists (0.7ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'taken_nickname' LIMIT 1
SQL (0.5ms) INSERT INTO "customers" ("name", "surname", "nickname", "email", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["name", "Rhea"], ["surname", "Swift"], ["nickname", "taken_nickname"], ["email", "brandyn#olson.ca"], ["encrypted_password", "$2a$04$TEtF/1Y2OL4zw5h.9coJBupMQaRqTESiuLThVY9sGT91oRkLEd1W."], ["created_at", "2015-11-27 15:45:19.022284"], ["updated_at", "2015-11-27 15:45:19.022284"]]
(0.3ms) RELEASE SAVEPOINT active_record_1
Customer Exists (0.8ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'laurine_boyer' LIMIT 1
(0.5ms) ROLLBACK
it is invalidy without email (FAILED - 1)
(0.3ms) BEGIN
(0.2ms) COMMIT
(0.2ms) BEGIN
(0.3ms) SAVEPOINT active_record_1
Customer Exists (0.6ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'kali' LIMIT 1
SQL (0.5ms) INSERT INTO "customers" ("name", "surname", "nickname", "email", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["name", "Bennett"], ["surname", "Stamm"], ["nickname", "kali"], ["email", "taken_mail"], ["encrypted_password", "$2a$04$fG2XjrqKQC.ABOpqnhfsFuLWTgYbdq5I.n9taI8i.70IQOG3gWx5G"], ["created_at", "2015-11-27 15:45:19.050392"], ["updated_at", "2015-11-27 15:45:19.050392"]]
(0.3ms) RELEASE SAVEPOINT active_record_1
(0.3ms) SAVEPOINT active_record_1
Customer Exists (0.7ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'taken_nickname' LIMIT 1
SQL (0.7ms) INSERT INTO "customers" ("name", "surname", "nickname", "email", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["name", "Kellen"], ["surname", "Okuneva"], ["nickname", "taken_nickname"], ["email", "marielle_robel#howe.co.uk"], ["encrypted_password", "$2a$04$hep6hAUJuFHmgC7CJRHUs.p6uGCKcnNCRoM9Yya22vIWBS1VcFBie"], ["created_at", "2015-11-27 15:45:19.065594"], ["updated_at", "2015-11-27 15:45:19.065594"]]
(0.4ms) RELEASE SAVEPOINT active_record_1
Customer Exists (0.7ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'earlene.rau' LIMIT 1
(0.4ms) ROLLBACK
it is invalidy without password confirmation (FAILED - 2)
(0.2ms) BEGIN
(0.2ms) COMMIT
(0.2ms) BEGIN
(0.3ms) SAVEPOINT active_record_1
Customer Exists (1.2ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'freddie' LIMIT 1
SQL (0.6ms) INSERT INTO "customers" ("name", "surname", "nickname", "email", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["name", "Camila"], ["surname", "Paucek"], ["nickname", "freddie"], ["email", "taken_mail"], ["encrypted_password", "$2a$04$hoJI92toiYmt/4nBQ8cBGOsXxhb.oPSgPRYz3ZG25IosSnKLkW6nu"], ["created_at", "2015-11-27 15:45:19.093570"], ["updated_at", "2015-11-27 15:45:19.093570"]]
(0.4ms) RELEASE SAVEPOINT active_record_1
(0.3ms) SAVEPOINT active_record_1
Customer Exists (0.7ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'taken_nickname' LIMIT 1
SQL (0.5ms) INSERT INTO "customers" ("name", "surname", "nickname", "email", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["name", "Johan"], ["surname", "Trantow"], ["nickname", "taken_nickname"], ["email", "betsy.kub#grahamaufderhar.co.uk"], ["encrypted_password", "$2a$04$5MD74LOZqAuYflxbzeTAU.ZzY9trd26IBK4Ah.PLoTeelOqSGAAKy"], ["created_at", "2015-11-27 15:45:19.108486"], ["updated_at", "2015-11-27 15:45:19.108486"]]
(0.3ms) RELEASE SAVEPOINT active_record_1
Customer Exists (0.6ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'sunny.kovacek' LIMIT 1
(0.3ms) ROLLBACK
it is invalidy if password and password_confirmation do not match (FAILED - 3)
(0.4ms) BEGIN
(0.4ms) COMMIT
(0.4ms) BEGIN
(0.3ms) SAVEPOINT active_record_1
Customer Exists (0.6ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'alexandrine' LIMIT 1
SQL (0.5ms) INSERT INTO "customers" ("name", "surname", "nickname", "email", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["name", "Elna"], ["surname", "Lowe"], ["nickname", "alexandrine"], ["email", "taken_mail"], ["encrypted_password", "$2a$04$vdlgun.EqNJ1J9V7BO5ra.xCU1KZxCq4rjOTurlFiiwafBMe0WysS"], ["created_at", "2015-11-27 15:45:19.137614"], ["updated_at", "2015-11-27 15:45:19.137614"]]
(0.3ms) RELEASE SAVEPOINT active_record_1
(0.3ms) SAVEPOINT active_record_1
Customer Exists (0.9ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'taken_nickname' LIMIT 1
SQL (0.6ms) INSERT INTO "customers" ("name", "surname", "nickname", "email", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["name", "Julius"], ["surname", "Ruecker"], ["nickname", "taken_nickname"], ["email", "lizzie#steuberwest.us"], ["encrypted_password", "$2a$04$TtVbUrUKkjRAkB6nGWGZAeMIhDPTccHHc1RHF2F4IcDy88gU2kpyS"], ["created_at", "2015-11-27 15:45:19.178343"], ["updated_at", "2015-11-27 15:45:19.178343"]]
(0.3ms) RELEASE SAVEPOINT active_record_1
Customer Exists (0.8ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'eldred.green' LIMIT 1
(0.4ms) ROLLBACK
it is invalidy with an already used email (FAILED - 4)
(0.3ms) BEGIN
(0.2ms) COMMIT
(0.2ms) BEGIN
(0.3ms) SAVEPOINT active_record_1
Customer Exists (0.8ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'ron' LIMIT 1
SQL (0.7ms) INSERT INTO "customers" ("name", "surname", "nickname", "email", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["name", "Tito"], ["surname", "Barton"], ["nickname", "ron"], ["email", "taken_mail"], ["encrypted_password", "$2a$04$.Fy4UJqU7yPMqpv.vg7VM.KjZJSJ1ECsok8S8FGUw.19tVvT0PuQq"], ["created_at", "2015-11-27 15:45:19.207736"], ["updated_at", "2015-11-27 15:45:19.207736"]]
(0.3ms) RELEASE SAVEPOINT active_record_1
(0.3ms) SAVEPOINT active_record_1
Customer Exists (0.9ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'taken_nickname' LIMIT 1
SQL (0.8ms) INSERT INTO "customers" ("name", "surname", "nickname", "email", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["name", "Jacinthe"], ["surname", "Thompson"], ["nickname", "taken_nickname"], ["email", "malika_bradtke#price.us"], ["encrypted_password", "$2a$04$hx2GUv5eqTHKJTXuL6OZTOqB1cP5/6gER05SKXCLosoONtehnLm1i"], ["created_at", "2015-11-27 15:45:19.223800"], ["updated_at", "2015-11-27 15:45:19.223800"]]
(0.4ms) RELEASE SAVEPOINT active_record_1
Customer Exists (0.7ms) SELECT 1 AS one FROM "customers" WHERE "customers"."nickname" = 'taken_nickname' LIMIT 1
(0.3ms) ROLLBACK
it is invalidy with an already used nickname
Failures:
1) Customer it is invalidy without email
Failure/Error: expect(FactoryGirl.build(:customer, email: nil)).to_not be_valid
expected #<Customer id: nil, email: nil, encrypted_password: "$2a$04$QccYinmB2OkI09/BkPBKY.Jp7zuygysDBc3PFfqQSqi...", name: "Camren", surname: "Ortiz", nickname: "laurine_boyer", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: nil, updated_at: nil, menu_visualization_type: true> not to be valid
# ./spec/models/customer_spec.rb:23:in `block (2 levels) in <top (required)>'
2) Customer it is invalidy without password confirmation
Failure/Error: expect(FactoryGirl.build(:customer, password_confirmation: nil)).to_not be_valid
expected #<Customer id: nil, email: "josiane.abbott#orn.info", encrypted_password: "$2a$04$K7aJMMwMsGNawdX4rMIg0uZkD0IiuNEN3Y6BlnMeUtr...", name: "Emmett", surname: "Crona", nickname: "earlene.rau", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: nil, updated_at: nil, menu_visualization_type: true> not to be valid
# ./spec/models/customer_spec.rb:26:in `block (2 levels) in <top (required)>'
3) Customer it is invalidy if password and password_confirmation do not match
Failure/Error: expect(FactoryGirl.build(:customer, password_confirmation: 'antonioross')).to_not be_valid
expected #<Customer id: nil, email: "roselyn#streich.us", encrypted_password: "$2a$04$N0Pdll6HtrBf1bbv7K4g/eCUDeBD41SgtLMC8QSp9Ve...", name: "Stephania", surname: "O'Reilly", nickname: "sunny.kovacek", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: nil, updated_at: nil, menu_visualization_type: true> not to be valid
# ./spec/models/customer_spec.rb:29:in `block (2 levels) in <top (required)>'
4) Customer it is invalidy with an already used email
Failure/Error: expect(FactoryGirl.build(:customer, email: 'taken_mail')).to_not be_valid
expected #<Customer id: nil, email: "taken_mail", encrypted_password: "$2a$04$m2ZUU3zA75.FKel0wyXEEu8gukmM3V/R1ZORwpzweZb...", name: "Adele", surname: "Morar", nickname: "eldred.green", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: nil, updated_at: nil, menu_visualization_type: true> not to be valid
# ./spec/models/customer_spec.rb:33:in `block (2 levels) in <top (required)>'
Finished in 2.6 seconds (files took 5.69 seconds to load)
8 examples, 4 failures
Failed examples:
rspec ./spec/models/customer_spec.rb:22 # Customer it is invalidy without email
rspec ./spec/models/customer_spec.rb:25 # Customer it is invalidy without password confirmation
rspec ./spec/models/customer_spec.rb:28 # Customer it is invalidy if password and password_confirmation do not match
rspec ./spec/models/customer_spec.rb:32 # Customer it is invalidy with an already used email
I'm very confused, some test working some don't
I agree with bu-oz, validating attributes that Devise manages is redundant, but if you want, you can do it like this:
it 'is invalid without email' do
expect{ User.create!(FactoryGirl.attributes_for(:user, email: nil)) }.to raise_error(ActiveRecord::RecordInvalid)
end
In addition to the exception class you may also pass the exception message to raise_error, to be sure why exactly the record is invalid.
I have used carrierwave in my application, but some reason I am getting this error --> Unpermitted parameters: avatar even thought I have permitted params.
I am using nested_form with Single Table Inheritance
here are the codes --> removed_url
and here are the server logs:
Started POST "/alerts" for 127.0.0.1 at 2014-05-05 15:44:51 -0500
Processing by AlertsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"jRaArdof0tbBHCXmdPqNiNpainmqliIx0sS9HdaBEcw=", "alert"=>{"victims_attributes"=>{"0"=>{"first_name"=>"victim1", "last_name"=>"victim1", "race"=>"race", "gender"=>"gender", "hair_color"=>"black", "eye_color"=>"black", "height_ft"=>"12", "height_inch"=>"12", "age"=>"12", "age_unit"=>"month", "birth_date"=>"05/02/2014", "weight"=>"125", "additional_info"=>"125", "images_attributes"=>{"0"=>{"avatar"=>[#<ActionDispatch::Http::UploadedFile:0x00000007f23350 #tempfile=#<Tempfile:C:/Users/jk12907/AppData/Local/Temp/RackMultipart20140505-56936-1neutn>, #original_filename="IMG_4470.JPG", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"alert[victims_attributes][0][images_attributes][0][avatar][]\"; filename=\"IMG_4470.JPG\"\r\nContent-Type: image/jpeg\r\n">]}}, "_destroy"=>"false"}}, "created_at"=>"2014/05/07 15:43", "nic"=>"nic", "investigating_officer_name"=>"officername", "investigating_officer_title"=>"officername", "investigating_officer_phone"=>"officername", "agency_name"=>"agencyname", "agency_phone"=>"agencyphone", "reporting_agency_phone"=>"agencyphone", "reporting_agency_email"=>"agencyemail", "last_seen"=>"2014/05/06 15:43", "last_known_address"=>"address", "last_known_city"=>"city", "last_known_state"=>"state", "last_known_county"=>"travis", "last_known_zip"=>"78660", "site_of_incident"=>"site of incident", "suspects_attributes"=>{"0"=>{"first_name"=>"suspect", "last_name"=>"suspect", "race"=>"asian", "gender"=>"male", "hair_color"=>"black", "eye_color"=>"black", "height_ft"=>"12", "height_inch"=>"45", "age"=>"12", "age_unit"=>"months", "birth_date"=>"05/02/2014", "weight"=>"145", "additional_info"=>"add info", "_destroy"=>"false"}}, "vehicles_attributes"=>{"0"=>{"make"=>"ford", "model"=>"ford", "style"=>"make", "year"=>"1995", "color"=>"black", "license_plate_number"=>"TYX", "license_plate_state"=>"TX", "additional_info"=>"add info", "_destroy"=>"false"}}}, "commit"=>"Create Alert"}
User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 8 ORDER BY "users"."id" ASC LIMIT 1
Unpermitted parameters: avatar
(0.0ms) BEGIN
SQL (0.0ms) INSERT INTO "alerts" ("agency_name", "agency_phone", "created_at", "investigating_officer_name", "investigating_officer_phone", "investigating_officer_title", "last_known_address", "last_known_city", "last_known_county", "last_known_state", "last_known_zip", "last_seen", "nic", "reporting_agency_email", "reporting_agency_phone", "site_of_incident", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) RETURNING "id" [["agency_name", "agencyname"], ["agency_phone", "agencyphone"], ["created_at", "2014-05-07 15:43:00.000000"], ["investigating_officer_name", "officername"], ["investigating_officer_phone", "officername"], ["investigating_officer_title", "officername"], ["last_known_address", "address"], ["last_known_city", "city"], ["last_known_county", "travis"], ["last_known_state", "state"], ["last_known_zip", "78660"], ["last_seen", "2014-05-06 15:43:00.000000"], ["nic", "nic"], ["reporting_agency_email", "agencyemail"], ["reporting_agency_phone", "agencyphone"], ["site_of_incident", "site of incident"], ["updated_at", "2014-05-05 20:44:51.406138"]]
SQL (1.0ms) INSERT INTO "vehicles" ("additional_info", "alert_id", "color", "created_at", "license_plate_number", "license_plate_state", "make", "model", "style", "updated_at", "year") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING "id" [["additional_info", "add info"], ["alert_id", 23], ["color", "black"], ["created_at", "2014-05-05 20:44:51.409138"], ["license_plate_number", "TYX"], ["license_plate_state", "TX"], ["make", "ford"], ["model", "ford"], ["style", "make"], ["updated_at", "2014-05-05 20:44:51.409138"], ["year", 1995]]
SQL (0.0ms) INSERT INTO "people" ("additional_info", "age", "age_unit", "alert_id", "birth_date", "created_at", "eye_color", "first_name", "gender", "hair_color", "height_ft", "height_inch", "last_name", "race", "type", "updated_at", "weight") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) RETURNING "id" [["additional_info", "125"], ["age", 12], ["age_unit", "month"], ["alert_id", 23], ["birth_date", "2014-02-05"], ["created_at", "2014-05-05 20:44:51.411138"], ["eye_color", "black"], ["first_name", "victim1"], ["gender", "gender"], ["hair_color", "black"], ["height_ft", 12], ["height_inch", 12], ["last_name", "victim1"], ["race", "race"], ["type", "Victim"], ["updated_at", "2014-05-05 20:44:51.411138"], ["weight", 125]]
SQL (0.0ms) INSERT INTO "images" ("created_at", "person_id", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["created_at", "2014-05-05 20:44:51.414138"], ["person_id", 42], ["updated_at", "2014-05-05 20:44:51.414138"]]
SQL (0.0ms) INSERT INTO "people" ("additional_info", "age", "age_unit", "alert_id", "birth_date", "created_at", "eye_color", "first_name", "gender", "hair_color", "height_ft", "height_inch", "last_name", "race", "type", "updated_at", "weight") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) RETURNING "id" [["additional_info", "add info"], ["age", 12], ["age_unit", "months"], ["alert_id", 23], ["birth_date", "2014-02-05"], ["created_at", "2014-05-05 20:44:51.416138"], ["eye_color", "black"], ["first_name", "suspect"], ["gender", "male"], ["hair_color", "black"], ["height_ft", 12], ["height_inch", 45], ["last_name", "suspect"], ["race", "asian"], ["type", "Suspect"], ["updated_at", "2014-05-05 20:44:51.416138"], ["weight", 145]]
(19.0ms) COMMIT
Redirected to http://127.0.0.1:3000/alerts
Completed 302 Found in 97ms (ActiveRecord: 21.0ms)
I have permitted the params in alerts_controller, people_controller and images_controller
and second question I have is, I have mention the dir to upload
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
am I suppose to see image uploaded to 'uploads/' folder of my c drive? I have storage :file on my avatar_uploader.rb file
please let me know what I am doing wrong? First time using Carrierwave here
any helps appreciate
Remove :multiple => true option from alerts/app/views/alerts/_victim.html.erb
Currently, file_field for avatar looks like:
<%= p.file_field :avatar, :multiple => true, class:'form-control input-normal' %>
Your file_field should look like:
<%= p.file_field :avatar, class:'form-control input-normal' %>
With the :multiple => true option :avatar field is send as Array upon form submission.
But as per your params hash, you are not expecting an array so you receive an Unpermitted parameters: avatar