I'm working on a tagged blog system using rails. Now it works using join table, but I have some doubt on performance.
Now every time I create a blog and its associating tags, it commits to database every single statement. I think better practice should be patch all these statements and commit to database only once. Is it possible in rails?
Create log dump:
Started POST "/articles" for 127.0.0.1 at 2014-08-29 15:30:48 -0400
Processing by ArticlesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"K4rWQEh0810X2jMe/Z9pC/PN2WeOcO0F0TkjKUZTPec=", "title"=>"test27", "text"=>"ddddd", "tag"=>"a,k,g", "commit"=>"Submit"}
Unpermitted parameters: utf8, authenticity_token, tag, commit
(0.9ms) BEGIN
SQL (0.3ms) INSERT INTO `articles` (`created_at`, `text`, `title`, `updated_at`) VALUES ('2014-08-29 19:30:48', 'ddddd', 'test27', '2014-08-29 19:30:48')
(0.2ms) COMMIT
Tag Load (0.3ms) SELECT `tags`.* FROM `tags` WHERE `tags`.`name` = 'a' LIMIT 1
(0.2ms) BEGIN
SQL (0.3ms) INSERT INTO `articles_tags` (`article_id`, `tag_id`) VALUES (28, 1)
(0.2ms) COMMIT
Tag Load (0.2ms) SELECT `tags`.* FROM `tags` WHERE `tags`.`name` = 'k' LIMIT 1
(0.1ms) BEGIN
SQL (0.2ms) INSERT INTO `tags` (`name`) VALUES ('k')
(0.1ms) COMMIT
(0.1ms) BEGIN
SQL (0.3ms) INSERT INTO `articles_tags` (`article_id`, `tag_id`) VALUES (28, 17)
(8.3ms) COMMIT
Tag Load (0.3ms) SELECT `tags`.* FROM `tags` WHERE `tags`.`name` = 'g' LIMIT 1
(0.1ms) BEGIN
SQL (0.2ms) INSERT INTO `tags` (`name`) VALUES ('g')
(0.1ms) COMMIT
(0.1ms) BEGIN
SQL (0.4ms) INSERT INTO `articles_tags` (`article_id`, `tag_id`) VALUES (28, 18)
(0.2ms) COMMIT
Model design:
class Article < ActiveRecord::Base
has_and_belongs_to_many :tag
end
class Tag < ActiveRecord::Base
has_and_belongs_to_many :article, :uniq => true
end
Blog create code:
def create
#article = Article.new(article_params)
tag_arr = params[:tag].split(',')
if #article.save
tag_arr.each do |name|
tag = Tag.find_or_create_by(name: name) # create a new tag only if tag.name not exist
#article.tag << tag
end
redirect_to #article
else
render 'new'
end
end
To save the article and tags in a single transaction, wrap the operations in a transaction block.
def create
#article = Article.new(article_params)
tag_arr = params[:tag].split(',')
Article.transaction do
if #article.save
tag_arr.each do |name|
article.tags.find_or_create_by(name: name)
end
end
end
if #article.new_record?
render 'new'
else
redirect_to #article
end
end
This will result in SQL queries something like:
(0.9ms) BEGIN
SQL (0.3ms) INSERT INTO `articles` (`created_at`, `text`, `title`, `updated_at`) VALUES ('2014-08-29 19:30:48', 'ddddd', 'test27', '2014-08-29 19:30:48')
Tag Load (0.3ms) SELECT `tags`.* FROM `tags` WHERE `tags`.`name` = 'a' LIMIT 1
SQL (0.3ms) INSERT INTO `articles_tags` (`article_id`, `tag_id`) VALUES (28, 1)
Tag Load (0.2ms) SELECT `tags`.* FROM `tags` WHERE `tags`.`name` = 'k' LIMIT 1
SQL (0.2ms) INSERT INTO `tags` (`name`) VALUES ('k')
SQL (0.3ms) INSERT INTO `articles_tags` (`article_id`, `tag_id`) VALUES (28, 17)
Tag Load (0.3ms) SELECT `tags`.* FROM `tags` WHERE `tags`.`name` = 'g' LIMIT 1
SQL (0.2ms) INSERT INTO `tags` (`name`) VALUES ('g')
SQL (0.4ms) INSERT INTO `articles_tags` (`article_id`, `tag_id`) VALUES (28, 18)
(0.2ms) COMMIT
Related
I'm trying to do what I think should be simple: do a simple edit on a single text string field with the default update action. But it just doesn't seem to work, despite many attempts and alterations.
There are no errors and the flash message responds successfully, but information isn't saved to the database at all:
routes.rb
resources :interviews do
resources :invitations do
put :accept
end
end
views/invitations/edit.html.haml
= simple_form_for [#interview, #invitation] do |f|
= f.error_notification
= f.input :testing
= f.submit 'Edit Invitstion', :class => 'button small'
controllers/invitations_controller.rb
def update
#invitation = Invitation.find(params[:id])
#interview = Interview.find(params[:interview_id])
#invitation.update_attributes(invitation_params)
if #invitation.update_attributes(invitation_params)
redirect_to edit_interview_invitation_path(#interview, #invitation), notice: "Your profile has been successfully updated."
else
render action: "edit"
end
end
private
def invitation_params
params.permit(:user_id, :interview_id, :invitation_id, :session_time, :workflow_state, :testing)
end
And here's the log:
Started PATCH "/interviews/3/invitations/7" for ::1 at 2016-05-15 19:01:52 +0800
Processing by InvitationsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"o0U5t0yPN0aE2er+DWK0uxqRGyp4ywfdSrEfvwiSQ3UUaOnr3Fd0raFs1IUqVzizKoqxRU0DDpmvysntB9fdhQ==", "invitation"=>{"interview_id"=>"3", "workflow_state"=>"invited", "session_time"=>"", "testing"=>"testtesttest"}, "commit"=>"Edit Invitstion", "interview_id"=>"3", "id"=>"7"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 7]]
Invitation Load (0.2ms) SELECT "invitations".* FROM "invitations" WHERE "invitations"."id" = $1 LIMIT 1 [["id", 7]]
Role Load (0.2ms) SELECT "roles".* FROM "roles" WHERE "roles"."id" = $1 LIMIT 1 [["id", 3]]
Interview Load (0.2ms) SELECT "interviews".* FROM "interviews" WHERE "interviews"."id" = $1 ORDER BY created_at DESC LIMIT 1 [["id", 3]]
CACHE (0.0ms) SELECT "invitations".* FROM "invitations" WHERE "invitations"."id" = $1 LIMIT 1 [["id", "7"]]
CACHE (0.0ms) SELECT "interviews".* FROM "interviews" WHERE "interviews"."id" = $1 ORDER BY created_at DESC LIMIT 1 [["id", "3"]]
Unpermitted parameters: utf8, _method, authenticity_token, invitation, commit, id
(0.1ms) BEGIN
Invitation Exists (0.4ms) SELECT 1 AS one FROM "invitations" WHERE ("invitations"."user_id" = 3 AND "invitations"."id" != 7 AND "invitations"."interview_id" = 3) LIMIT 1
(0.1ms) COMMIT
Redirected to http://localhost:3000/interviews/3/invitations/7/edit
Completed 302 Found in 12ms (ActiveRecord: 1.6ms)
Started GET "/interviews/3/invitations/7/edit" for ::1 at 2016-05-15 19:01:52 +0800
Processing by InvitationsController#edit as HTML
Parameters: {"interview_id"=>"3", "id"=>"7"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 7]]
Invitation Load (0.3ms) SELECT "invitations".* FROM "invitations" WHERE "invitations"."id" = $1 LIMIT 1 [["id", 7]]
Role Load (0.2ms) SELECT "roles".* FROM "roles" WHERE "roles"."id" = $1 LIMIT 1 [["id", 3]]
Interview Load (0.2ms) SELECT "interviews".* FROM "interviews" WHERE "interviews"."id" = $1 ORDER BY created_at DESC LIMIT 1 [["id", 3]]
Rendered invitations/edit.html.haml within layouts/application (6.1ms)
Completed 200 OK in 48ms (Views: 39.1ms | ActiveRecord: 1.6ms)
Check the format of your params object in your logs. Your invitation params are being passed within the params["invitation"] key, yet you're whitelisting and updating your object based on the params in the root params hash.
Also note that your logs are reporting that you're trying to update your invitation with unpermitted params:
Unpermitted parameters: utf8, _method, authenticity_token, invitation, commit, id
You can fix this by simply updating your invitation_params to use params[:invitation] rather than params like so:
def invitation_params
params.require(:invitation).permit(:user_id, :interview_id, :invitation_id, :session_time, :workflow_state, :testing)
end
Also, you might want to consider raising an error if you're trying to update a parameter that's not whitelisted to prevent these sorts of issues in the future.
In your rails config:
config.action_controller.action_on_unpermitted_parameters = :raise
I have three main Classes: Users, Vocabs and Tags. A User has many Tags. Tags has-and-belongs-to-many Vocabs (and the other way around).
How can I order a collection of Tags when getting them through a Vocab-Object?
#vocab.tag
gets the tags from the joins table, which has no created_at column.
Is there a handy way to solve this problem?
I am pretty new to Rails so excuse me if this is obvious.
EDIT: I just tried
#tags = #vocab.tags.order('tags.created_at DESC')
but without success.
The computer says:
Started GET "/users/1/vocabs/61" for 127.0.0.1 at 2014-12-11 15:41:15 +0100
Processing by VocabsController#show as HTML
Parameters: {"user_id"=>"1", "id"=>"61"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Vocab Load (0.3ms) SELECT "vocabs".* FROM "vocabs" WHERE "vocabs"."user_id" = ? AND "vocabs"."id"
= ? ORDER BY created_at DESC LIMIT 1 [["user_id", 1], ["id", 61]]
Tag Load (0.5ms) SELECT DISTINCT "tags".* FROM "tags" INNER JOIN "tags_vocabs" ON "tags"."id" =
"tags_vocabs"."tag_id" WHERE "tags_vocabs"."vocab_id" = ? [["vocab_id", 61]]
Rendered shared/_error_messages.html.erb (0.2ms)
Rendered vocabs/show.html.erb within layouts/application (10.7ms)
Rendered layouts/_shim.html.erb (0.1ms)
Rendered layouts/_header.html.erb (1.1ms)
Completed 200 OK in 602ms (Views: 587.3ms | ActiveRecord: 1.2ms)
The controller action looks like this:
def new_tag
#user = current_user
#vocab = #user.vocabs.find(params[:id])
#tags = #vocab.tags.order('tags.created_at DESC')
#tag = current_user.tags.build(name: params[:tag])
if #tag.save
#vocab.tags<<#tag
flash.now[:success] ='Tag successfully created.'
redirect_to user_vocab_path(#user, #vocab)
else
flash.now[:danger] = "Tag could not be created!"
render :action => "show"
end
end
From last two days i try expect whats going on in my app. This is my problem:
My model:
class User
has_many :orders
---
class Order
belongs_to :user
has_and_belongs_to_many :contributors, class_name: 'User'
Situation:
User can create order, next for this order can add contributors(other users) with
<%= collection_check_boxes(:order, :contributor_ids, #prac, :id, :to_s) %>
After that in my custom action in OrdersController i have something like this:
#order.contributors.each do |u|
u.orders << #order
end
Here i want add this order to list of contributors(users) orders. Unfortunately this work only for last contributor(user). Below log from my console:
Started PATCH "/orders/282/zatwierdz" for 127.0.0.1 at 2014-07-01 08:48:59 +0200
Processing by OrdersController#zatwierdz as HTML
Parameters: {"authenticity_token"=>"hxWUnazKLoS9t8bVmOAMeIxdo/KYuO33bUeuQZYgeV
k=", "id"=>"282"}
User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 32 OR
DER BY "users"."id" ASC LIMIT 1
Role Load (0.0ms) SELECT "roles".* FROM "roles" WHERE "roles"."id" = ? LIMI
T 1 [["id", 4]]
Order Load (0.0ms) SELECT "orders".* FROM "orders" WHERE "orders"."id" = ?
ORDER BY created_at DESC LIMIT 1 [["id", 282]]
OrderItem Exists (0.0ms) SELECT 1 AS one FROM "order_items" WHERE "order_it
ems"."order_id" = ? LIMIT 1 [["order_id", 282]]
(0.0ms) begin transaction
SQL (0.0ms) UPDATE "orders" SET "status" = ?, "updated_at" = ? WHERE "orders"
."id" = 282 [["status", 1], ["updated_at", "2014-07-01 06:48:59.486472"]]
(62.5ms) commit transaction
User Load (0.0ms) SELECT "users".* FROM "users" INNER JOIN "orders_users" ON
"users"."id" = "orders_users"."user_id" WHERE "orders_users"."order_id" = ? [["
order_id", 282]]
(0.0ms) begin transaction
(0.0ms) commit transaction
(0.0ms) begin transaction
SQL (0.0ms) UPDATE "orders" SET "updated_at" = ?, "user_id" = ? WHERE "orders
"."id" = 282 [["updated_at", "2014-07-01 06:48:59.564595"], ["user_id", 33]]
(78.1ms) commit transaction
(0.0ms) begin transaction
SQL (0.0ms) UPDATE "orders" SET "updated_at" = ?, "user_id" = ? WHERE "orders
"."id" = 282 [["updated_at", "2014-07-01 06:48:59.642719"], ["user_id", 35]]
(78.1ms) commit transaction
(0.0ms) begin transaction
SQL (0.0ms) UPDATE "orders" SET "updated_at" = ?, "user_id" = ? WHERE "orders
"."id" = 282 [["updated_at", "2014-07-01 06:48:59.720842"], ["user_id", 36]]
(109.4ms) commit transaction
(0.0ms) begin transaction
SQL (0.0ms) UPDATE "orders" SET "updated_at" = ?, "user_id" = ? WHERE "orders
"."id" = 282 [["updated_at", "2014-07-01 06:48:59.830215"], ["user_id", 37]]
(78.1ms) commit transaction
Redirected to http://localhost:3000/orders/282
Completed 302 Found in 437ms (ActiveRecord: 406.2ms)
I try use this action with callbacks and from model methods but nothing happened. Maybe better for this aprouch is to use other associations? Anny sugestions welcome.
Thx for help.
By doing:
#order.contributors.each do |u|
u.orders << #order
end
You are adding your order to the user.orders relationship, which you define as a many (Order) to one (User). The "has_many" orders on the User class is just the other side of the "belongs_to" user on the Order class. So yes, as per your model, an Order has one and only one user.
Now, if you want to be able to navigate your has_and_belongs_to_many relation from the User side, you need to define it there too.
I'm having a baffling problem. I have a LineItem model that accepts nested attributes for a Trackable and a Product. I am overriding the default trackable_attributes= and product_attributes= methods to allow me to find or initialize records. For example:
def trackable_attributes=(attributes)
_trackable = Project.find_or_initialize_by_id(attributes.delete("id"))
_trackable.attributes = attributes
self.trackable = _trackable
end
When I post to the LineItemController#create, even when there's only a logging statement in it, it runs all of the posted parameters as if I'm trying to build/create a new line item. I don't have any before_filters that would be doing this on the #create method.
def create
logger.info("LineItemsController#create")
end
Webserver logs:
Started POST "/line_items" for 127.0.0.1 at 2013-04-10 14:02:13 -0700
Processing by LineItemsController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"MY_SECRET_TOKEN", "line_item"=>{"trackable_type"=>"Project", "tax_rate"=>"0", "price"=>"0.00", "provided_on_formatted"=>"Apr 10", "trackable_attributes"=>{"company_attributes"=>{"id"=>"87", "name"=>"Handmade Design"}, "id"=>"45", "name"=>"MEdia Blitz"}, "product_attributes"=>{"id"=>"75"}, "name"=>"Design", "notes"=>"Yellow", "quantity"=>"0.00", "unit_price"=>"205.0"}, "commit"=>"+"}
Person Load (0.3ms) SELECT "people".* FROM "people" WHERE "people"."id" = 73 LIMIT 1
(0.1ms) begin transaction
(0.4ms) UPDATE "people" SET "last_request_at" = '2013-04-10 21:02:13.861629', "perishable_token" = 'kzsB5dnCOHfykO1XMMi9', "updated_at" = '2013-04-10 21:02:13.863622' WHERE "people"."id" = 73
[paperclip] Saving attachments.
(1.2ms) commit transaction
Account Load (0.2ms) SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = 369 LIMIT 1
Person Load (0.3ms) SELECT "people".* FROM "people" WHERE "people"."account_id" = 369 ORDER BY id LIMIT 1
{"company_attributes"=>{"id"=>"87", "name"=>"Handmade Design"}, "id"=>"45", "name"=>"MEdia Blitz"}
Project Load (0.2ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = 45 LIMIT 1
Company Load (0.2ms) SELECT "companies".* FROM "companies" WHERE "companies"."id" = 87 LIMIT 1
trackable_attributes=(attributes)
trackable assigned
{"id"=>"75"}
Product Load (0.2ms) SELECT "products".* FROM "products" WHERE "products"."id" = 75 LIMIT 1
product_attributes=(attributes)
product assigned
LineItemsController#create
Notice that I have many logging statements scattered through my custom accepts_nested_attributes_for setters that are being called before the #create method even begins.
Is this normal? It seems to be causing problems with when I want to instantiate a new line_item the normal way in my LineItemsController#create method.
I'd really appreciate any help as I'm lost on where to start.
I'm trying to update a model object, and it keeps rolling back. Occassionaly protesting that it is a validation error. But it doesn't point to what is actually failing.
In the end, I tried to delete it, but in the deletion, it still fails validation.
Is there a way to debug this and find out exactly why/what is causing this?
Thanks
A typical response to an update or delete:
ActiveRecord::RecordNotSaved: ActiveRecord::RecordNotSaved
from /data/HQ_Channel2/releases/20111011173855/vendor/rails/activerecord/lib/active_record/base.rb:2551:in `save_without_validation!'
from /data/HQ_Channel2/releases/20111011173855/vendor/rails/activerecord/lib/active_record/validations.rb:1019:in `save_without_dirty!'
from /data/HQ_Channel2/releases/20111011173855/vendor/rails/activerecord/lib/active_record/dirty.rb:87:in `save_without_transactions!'
from /data/HQ_Channel2/releases/20111011173855/vendor/rails/activerecord/lib/active_record/transactions.rb:200:in `save!'
from /data/HQ_Channel2/releases/20111011173855/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
And for more evidence, this is the stack from the appication when I try to create a new object:
Processing OrganizationsController#create (for 127.0.0.1 at 2011-10-12 15:43:02) [POST]
Parameters: {"commit"=>"submit", "action"=>"create", "authenticity_token"=>"QxTT80hdtULmkt7PeUH5MG+BZ/5l+a22ry3EL49q1V8=", "controller"=>"organizations", "organization"=>{"city"=>"lkjlkj", "name"=>"asdfa", "contact_24"=>"1", "zip"=>"123123", "quick_description"=>"2342, 123, 3,2423, 2", "url"=>"www.martini494bistro.com/", "hq_url"=>"12341234", "map_it"=>"1", "street"=>"lkjlkj", "phone_work"=>"123123123123", "is_authorized"=>"1", "state"=>"NJ"}}
User Columns (2.2ms) SHOW FIELDS FROM `users`
User Load (4.4ms) SELECT * FROM `users` WHERE (`users`.`persistence_token` = '77ca6dea2961c5102be62d8e995e3f4bfdcb5bcfdf64a4e8361d2f3b49e9b377e6467d1a01a3fbe7fc6dab76382220b044d3782f6045130a2de047d8b8f0bd87') LIMIT 1
SQL (0.1ms) BEGIN
User Update (0.3ms) UPDATE `users` SET `updated_at` = '2011-10-12 19:43:02', `perishable_token` = 'YP8Ivses9OgR6LtrNBvF', `last_request_at` = '2011-10-12 19:43:02' WHERE `id` = 2953
Solr Update (7.0ms) <?xml version="1.0" encoding="UTF-8"?><add><doc><field name="type">User</field><field name="type">ActiveRecord::Base</field><field name="id">User 2953</field><field name="email_s">asdfasdf#asdfasdf.com</field><field name="name_s">asdfadsf adfasdf</field><field name="first_name_s">asdfadsf</field><field name="created_at_d">2011-10-12T19:39:36Z</field><field name="class_name">User</field><field name="last_name_s">adfasdf</field><field name="name_text">asdfadsf adfasdf</field><field name="email_text">asdfasdf#asdfasdf.com</field><field name="last_name_text">adfasdf</field><field name="first_name_text">asdfadsf</field></doc></add>
SQL (0.6ms) COMMIT
SQL (1.1ms) SHOW TABLES
Organization Columns (5.4ms) SHOW FIELDS FROM `organizations`
Organization Load (2.9ms) SELECT `organizations`.* FROM `organizations` INNER JOIN `organizations_users` ON `organizations`.id = `organizations_users`.organization_id WHERE ((`organizations_users`.user_id = 2953))
SQL (0.1ms) BEGIN
Organization Load (1.1ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`name`) = BINARY 'asdfa') LIMIT 1
Organization Load (2.2ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`hq_url`) = BINARY '12341234') LIMIT 1
QuickFact Columns (1.3ms) SHOW FIELDS FROM `quick_facts`
SQL (2.2ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
SQL (0.1ms) ROLLBACK
SQL (3.1ms) BEGIN
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`name`) = BINARY 'asdfa') LIMIT 1
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`hq_url`) = BINARY '12341234') LIMIT 1
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
SQL (0.1ms) ROLLBACK
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`name`) = BINARY 'asdfa') LIMIT 1
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`hq_url`) = BINARY '12341234') LIMIT 1
SQL (0.1ms) BEGIN
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`name`) = BINARY 'asdfa') LIMIT 1
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`hq_url`) = BINARY '12341234') LIMIT 1
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
SQL (0.1ms) ROLLBACK
SQL (0.1ms) BEGIN
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`name`) = BINARY 'asdfa') LIMIT 1
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`hq_url`) = BINARY '12341234') LIMIT 1
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
SQL (0.1ms) ROLLBACK
Rendering template within layouts/application
Rendering organizations/new
Rendered organizations/_form (4.2ms)
Rendered layouts/_head (2.7ms)
SQL (0.7ms) SELECT count(*) AS count_all FROM `organizations` INNER JOIN `organizations_users` ON `organizations`.id = `organizations_users`.organization_id WHERE ((`organizations_users`.user_id = 2953))
Rendered layouts/_login_status_new (2.1ms)
Rendered layouts/_header_new (2.9ms)
Rendered layouts/_need_login (0.2ms)
Rendered layouts/_already_have_tooltip (0.1ms)
Completed in 227923ms (View: 34, DB: 29) | 200 OK [http://localhost/organizations]
SQL (0.1ms) SET NAMES 'utf8'
SQL (0.1ms) SET NAMES 'utf8'
SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
Processing DynamicStylesheetsController#image_css to css (for 127.0.0.1 at 2011-10-12 15:46:50) [GET]
Parameters: {"format"=>"css", "action"=>"image_css", "controller"=>"dynamic_stylesheets"}
At a guess, these lines:
SQL (2.2ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
SQL (0.1ms) ROLLBACK
.. mean that you have a uniqueness validation that's failing because the null value is "taken".