Rails 4: Double request/response/select/insert - ruby-on-rails

in my rails 4 app I noticed, that when I create new comment, every request/response are doubles. anybody know why?
I'm using ajax
this is my logs:
Started POST "/comments" for 127.0.0.1 at 2015-03-25 21:07:06 +0400
Started POST "/comments" for 127.0.0.1 at 2015-03-25 21:07:06 +0400
Processing by CommentsController#create as JS
Processing by CommentsController#create as JS
Parameters: {"utf8"=>"✓", "recipe_id"=>"1", "comment"=>"llkl;kl;k;l", "commit"=>"Add Comment"}
Parameters: {"utf8"=>"✓", "recipe_id"=>"1", "comment"=>"llkl;kl;k;l", "commit"=>"Add Comment"}
Recipe Load (0.1ms) SELECT "recipes".* FROM "recipes" WHERE "recipes"."id" = ? LIMIT 1 [["id", 1]]
Recipe Load (0.1ms) SELECT "recipes".* FROM "recipes" WHERE "recipes"."id" = ? LIMIT 1 [["id", 1]]
User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
(0.1ms) begin transaction
(0.1ms) begin transaction
SQL (0.2ms) INSERT INTO "comments" ("commentable_id", "commentable_type", "comment", "user_id", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["commentable_id", 1], ["commentable_type", "Recipe"], ["comment", "llkl;kl;k;l"], ["user_id", 1], ["created_at", "2015-03-25 17:07:06.221648"], ["updated_at", "2015-03-25 17:07:06.221648"]]
SQL (0.2ms) INSERT INTO "comments" ("commentable_id", "commentable_type", "comment", "user_id", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["commentable_id", 1], ["commentable_type", "Recipe"], ["comment", "llkl;kl;k;l"], ["user_id", 1], ["created_at", "2015-03-25 17:07:06.221648"], ["updated_at", "2015-03-25 17:07:06.221648"]]
(17.8ms) commit transaction
(17.8ms) commit transaction
Comment Load (2.0ms) SELECT "comments".* FROM "comments" WHERE "comments"."commentable_id" = ? AND "comments"."commentable_type" = ? ORDER BY created_at DESC LIMIT 15 OFFSET 0 [["commentable_id", 1], ["commentable_type", "Recipe"]]
Comment Load (2.0ms) SELECT "comments".* FROM "comments" WHERE "comments"."commentable_id" = ? AND "comments"."commentable_type" = ? ORDER BY created_at DESC LIMIT 15 OFFSET 0 [["commentable_id", 1], ["commentable_type", "Recipe"]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
Rendered recipes/_comments.html.erb (6.2ms)
Rendered recipes/_comments.html.erb (6.2ms)
Rendered comments/create.js.erb (15.3ms)
Rendered comments/create.js.erb (15.3ms)
Completed 200 OK in 54ms (Views: 16.4ms | ActiveRecord: 20.3ms)
Completed 200 OK in 54ms (Views: 16.4ms | ActiveRecord: 20.3ms)

Related

How do I eliminate this n+1 query?

Models:
class Device < ApplicationRecord
has_many :device_locations
has_many :locations, through: :device_locations do
def previous
order('device_locations.removed_at DESC').first
end
end
end
class Location < ApplicationRecord
has_many :device_locations
has_many :devices, through: :device_locations
end
class DeviceLocation < ApplicationRecord
belongs_to :device
belongs_to :location
end
Controller Action:
# LocationsController
def show
#location = Location.find(params[:id])
#device_locations = #location.device_locations.includes(:device).where(removed_at: nil)
end
View:
<table>
<tr><th>Name</th><th>Install Date</th><th>Uninstall Date</th><th>Previous Location</th></tr>
<%- #device_locations.each do |device_location| %>
<tr>
<td><%= link_to device_location.device.name, device_location.device %></td>
<td><%= device_location.installed_at %></td>
<td><%= device_location.removed_at %></td>
<td><%= link_to device_location.device.locations.previous.name, device_location.device.locations.previous %></td>
</tr>
<% end %>
</table>
The difficulty here is avoiding the n+1 query generated by device_location.device.locations.previous.name. It's like I need to join the table to itself?
Without this column removed from the view the log reads:
Started GET "/locations/1" for ::1 at 2019-08-24 11:09:55 -0400
(0.1ms) SELECT sqlite_version(*)
Processing by LocationsController#show as HTML
Parameters: {"id"=>"1"}
Location Load (0.4ms) SELECT "locations".* FROM "locations" WHERE "locations"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
↳ app/controllers/locations_controller.rb:69:in `set_location'
Rendering locations/show.html.erb within layouts/application
DeviceLocation Load (14.6ms) SELECT "device_locations".* FROM "device_locations" WHERE "device_locations"."location_id" = ? AND "device_locations"."removed_at" IS NULL [["location_id", 1]]
↳ app/views/locations/show.html.erb:9
Device Load (1.0ms) SELECT "devices".* FROM "devices" WHERE "devices"."id" IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["id", 1], ["id", 5], ["id", 28], ["id", 35], ["id", 51], ["id", 57], ["id", 61], ["id", 86], ["id", 94], ["id", 99], ["id", 107], ["id", 115], ["id", 125], ["id", 139], ["id", 148], ["id", 151], ["id", 159], ["id", 164], ["id", 165], ["id", 168], ["id", 177]]
↳ app/views/locations/show.html.erb:9
Rendered locations/show.html.erb within layouts/application (Duration: 20.7ms | Allocations: 4172)
Completed 200 OK in 25ms (Views: 7.3ms | ActiveRecord: 15.9ms | Allocations: 6079)
With the column present it reads:
Started GET "/locations/1" for ::1 at 2019-08-24 11:10:51 -0400
Processing by LocationsController#show as HTML
Parameters: {"id"=>"1"}
Location Load (0.1ms) SELECT "locations".* FROM "locations" WHERE "locations"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
↳ app/controllers/locations_controller.rb:69:in `set_location'
Rendering locations/show.html.erb within layouts/application
DeviceLocation Load (0.4ms) SELECT "device_locations".* FROM "device_locations" WHERE "device_locations"."location_id" = ? AND "device_locations"."removed_at" IS NULL [["location_id", 1]]
↳ app/views/locations/show.html.erb:9
Device Load (0.2ms) SELECT "devices".* FROM "devices" WHERE "devices"."id" IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["id", 1], ["id", 5], ["id", 28], ["id", 35], ["id", 51], ["id", 57], ["id", 61], ["id", 86], ["id", 94], ["id", 99], ["id", 107], ["id", 115], ["id", 125], ["id", 139], ["id", 148], ["id", 151], ["id", 159], ["id", 164], ["id", 165], ["id", 168], ["id", 177]]
↳ app/views/locations/show.html.erb:9
Location Load (0.8ms) SELECT "locations".* FROM "locations" INNER JOIN "device_locations" ON "locations"."id" = "device_locations"."location_id" WHERE "device_locations"."device_id" = ? ORDER BY device_locations.removed_at DESC LIMIT ? [["device_id", 1], ["LIMIT", 1]]
↳ app/models/device.rb:5:in `previous'
CACHE Location Load (0.0ms) SELECT "locations".* FROM "locations" INNER JOIN "device_locations" ON "locations"."id" = "device_locations"."location_id" WHERE "device_locations"."device_id" = ? ORDER BY device_locations.removed_at DESC LIMIT ? [["device_id", 1], ["LIMIT", 1]]
↳ app/models/device.rb:5:in `previous'
... N times
CACHE Location Load (0.0ms) SELECT "locations".* FROM "locations" INNER JOIN "device_locations" ON "locations"."id" = "device_locations"."location_id" WHERE "device_locations"."device_id" = ? ORDER BY device_locations.removed_at DESC LIMIT ? [["device_id", 177], ["LIMIT", 1]]
↳ app/models/device.rb:5:in `previous'
Rendered locations/show.html.erb within layouts/application (Duration: 50.7ms | Allocations: 40363)
Completed 200 OK in 55ms (Views: 47.7ms | ActiveRecord: 5.3ms | Allocations: 42252)
Shauno, have you tried the Bullet gem? it helps you get rid of n+1 queries throughout your application by showing a notice at the bottom of pages when a n+1 query is detected, and it also suggests possible solutions.
https://github.com/flyerhzm/bullet
Just make sure to only add it to your development group in the gemfile.

Upgraded from SQLite3 to PG - db is 100 times slower

Just streamlined my dev environment and switched from SQLite3 to PG so it's the same on my production environment.
The same working code that I had before is now taking much, MUCH more time than it did before.
Haven't changed anything except installing pg.
Before PG:
Processing by CollectionsController#show as HTML
Parameters: {"keyword"=>"cat and dog towel", "id"=>"37"}
Collection Load (0.2ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = ? LIMIT ? [["id", 37], ["LIMIT", 1]]
Seller Load (0.2ms) SELECT "sellers".* FROM "sellers" WHERE "sellers"."id" = ? LIMIT ? [["id", 13], ["LIMIT", 1]]
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]]
(0.1ms) begin transaction
(0.1ms) commit transaction
Search Load (0.2ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = ? LIMIT ? [["term", "cat and dog towel"], ["LIMIT", 1]]
Listing Load (1.4ms) SELECT DISTINCT "listings".* FROM "listings" INNER JOIN "listings_searches" ON "listings"."id" = "listings_searches"."listing_id" WHERE "listings_searches"."search_id" = ? ORDER BY "listings"."id" ASC LIMIT ? [["search_id", 775], ["LIMIT", 1]]
Search Load (0.3ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = ? ORDER BY "searches"."id" ASC LIMIT ? [["term", "Beach Towel"], ["LIMIT", 1]]
(0.1ms) begin transaction
Search Exists (0.2ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = ? LIMIT ? [["term", "Beach Towel"], ["LIMIT", 1]]
SQL (0.5ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES (?, ?, ?) [["term", "Beach Towel"], ["created_at", "2018-06-18 12:47:58.519223"], ["updated_at", "2018-06-18 12:47:58.519223"]]
(7.0ms) commit transaction
Item Exists (0.3ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = ? AND "items"."collection_id" = 37 LIMIT ? [["search_id", 776], ["LIMIT", 1]]
(0.1ms) begin transaction
Collection Load (0.1ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = ? LIMIT ? [["id", 37], ["LIMIT", 1]]
Item Exists (0.2ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = ? AND "items"."search_id" = 776 LIMIT ? [["collection_id", 37], ["LIMIT", 1]]
SQL (2.3ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["collection_id", 37], ["search_id", 776], ["created_at", "2018-06-18 12:47:58.540021"], ["updated_at", "2018-06-18 12:47:58.540021"]]
(6.2ms) commit transaction
Started GET "/sellers/16" for 127.0.0.1 at 2018-06-18 15:48:00 +0300
Processing by SellersController#show as HTML
Parameters: {"id"=>"16"}
Search Load (5.5ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = ? ORDER BY "searches"."id" ASC LIMIT ? [["term", "Bath Towel"], ["LIMIT", 1]]
(0.1ms) begin transaction
Search Exists (0.2ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = ? LIMIT ? [["term", "Bath Towel"], ["LIMIT", 1]]
SQL (1.4ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES (?, ?, ?) [["term", "Bath Towel"], ["created_at", "2018-06-18 12:48:01.250699"], ["updated_at", "2018-06-18 12:48:01.250699"]]
Seller Load (0.3ms) SELECT "sellers".* FROM "sellers" WHERE "sellers"."id" = ? LIMIT ? [["id", 16], ["LIMIT", 1]]
(9.6ms) commit transaction
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]]
Item Exists (0.3ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = ? AND "items"."collection_id" = 37 LIMIT ? [["search_id", 777], ["LIMIT", 1]]
(0.1ms) begin transaction
Collection Load (0.3ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = ? LIMIT ? [["id", 37], ["LIMIT", 1]]
Item Exists (0.2ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = ? AND "items"."search_id" = 777 LIMIT ? [["collection_id", 37], ["LIMIT", 1]]
SQL (1.0ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["collection_id", 37], ["search_id", 777], ["created_at", "2018-06-18 12:48:01.285942"], ["updated_at", "2018-06-18 12:48:01.285942"]]
Shop Load (8.8ms) SELECT "shops".* FROM "shops" WHERE "shops"."seller_id" = ? ORDER BY "shops"."id" DESC LIMIT ? [["seller_id", 16], ["LIMIT", 1]]
(40.2ms) commit transaction
Rendering sellers/show.html.erb within layouts/application
(0.4ms) SELECT COUNT(*) FROM "listings" WHERE "listings"."shop_id" = 12
Listing Load (0.4ms) SELECT "listings".* FROM "listings" WHERE "listings"."shop_id" = 12 LIMIT ? OFFSET ? [["LIMIT", 24], ["OFFSET", 0]]
Rendered sellers/show.html.erb within layouts/application (4.8ms)
Rendered layouts/_shim.html.erb (0.4ms)
Rendered layouts/_rails_default.html.erb (93.9ms)
Rendered layouts/_meta.html.erb (0.3ms)
Seller Exists (0.3ms) SELECT 1 AS one FROM "sellers" WHERE "sellers"."user_id" = ? LIMIT ? [["user_id", 1], ["LIMIT", 1]]
Seller Load (0.3ms) SELECT "sellers".* FROM "sellers" WHERE "sellers"."user_id" = ? ORDER BY "sellers"."id" DESC LIMIT ? [["user_id", 1], ["LIMIT", 1]]
Rendered layouts/_header.html.erb (5.5ms)
Seller Load (0.3ms) SELECT "sellers".* FROM "sellers" WHERE "sellers"."user_id" = ? [["user_id", 1]]
Shop Load (0.3ms) SELECT "shops".* FROM "shops" WHERE "shops"."seller_id" = ? ORDER BY "shops"."id" DESC LIMIT ? [["seller_id", 13], ["LIMIT", 1]]
CACHE Shop Load (0.0ms) SELECT "shops".* FROM "shops" WHERE "shops"."seller_id" = ? ORDER BY "shops"."id" DESC LIMIT ? [["seller_id", 16], ["LIMIT", 1]]
Rendered layouts/_sidebar.html.erb (7.3ms)
Rendered layouts/_end_sidebar.html.erb (0.4ms)
Rendered layouts/_footer.html.erb (0.4ms)
Completed 200 OK in 212ms (Views: 120.5ms | ActiveRecord: 12.3ms)
After PG:
Started POST "/collections/1/item/choose.25" for 127.0.0.1 at 2018-06-18 16:56:12 +0300
Processing by ItemsController#choose as
Parameters: {"authenticity_token"=>"11+Rpf2qXEKhQ5vBJLWie2EBg1b2Dtrw8iIgoLwXyvake7+myDrVErcqTwNcPYAZ5xs+zFKXaJjwM7fTakXaoA==", "collection_id"=>"1"}
Collection Load (0.4ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Seller Load (0.6ms) SELECT "sellers".* FROM "sellers" WHERE "sellers"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Load (0.3ms) SELECT "items".* FROM "items" WHERE "items"."id" = $1 LIMIT $2 [["id", 25], ["LIMIT", 1]]
(0.1ms) BEGIN
Collection Load (0.5ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Search Load (0.9ms) SELECT "searches".* FROM "searches" WHERE "searches"."id" = $1 LIMIT $2 [["id", 31], ["LIMIT", 1]]
Item Exists (0.7ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND ("items"."id" != $2) AND "items"."search_id" = 31 LIMIT $3 [["collection_id", 1], ["id", 25], ["LIMIT", 1]]
SQL (0.8ms) UPDATE "items" SET "chosen" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["chosen", "t"], ["updated_at", "2018-06-18 13:56:12.465841"], ["id", 25]]
(2.7ms) COMMIT
(0.4ms) BEGIN
SQL (0.6ms) UPDATE "collections" SET "keyword" = $1, "updated_at" = $2 WHERE "collections"."id" = $3 [["keyword", "Bookish Candles"], ["updated_at", "2018-06-18 13:56:12.473173"], ["id", 1]]
(1.5ms) COMMIT
Search Load (0.6ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "Bookish Candles"], ["LIMIT", 1]]
Listing Load (4.1ms) SELECT DISTINCT "listings".* FROM "listings" INNER JOIN "listings_searches" ON "listings"."id" = "listings_searches"."listing_id" WHERE "listings_searches"."search_id" = $1 ORDER BY "listings"."id" ASC LIMIT $2 [["search_id", 31], ["LIMIT", 3]]
Search Load (0.7ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "soy candles"], ["LIMIT", 1]]
(0.2ms) BEGIN
Search Exists (0.8ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "soy candles"], ["LIMIT", 1]]
SQL (0.6ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "soy candles"], ["created_at", "2018-06-18 13:56:12.491262"], ["updated_at", "2018-06-18 13:56:12.491262"]]
(2.3ms) COMMIT
Item Exists (0.6ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 46], ["LIMIT", 1]]
(0.2ms) BEGIN
Collection Load (1.3ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.7ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 46 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (1.0ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 46], ["created_at", "2018-06-18 13:56:12.504381"], ["updated_at", "2018-06-18 13:56:12.504381"]]
(1.1ms) COMMIT
Search Load (0.8ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "book candle"], ["LIMIT", 1]]
(0.2ms) BEGIN
Search Exists (0.5ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "book candle"], ["LIMIT", 1]]
SQL (0.5ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "book candle"], ["created_at", "2018-06-18 13:56:14.812727"], ["updated_at", "2018-06-18 13:56:14.812727"]]
(2.8ms) COMMIT
Item Exists (0.7ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 47], ["LIMIT", 1]]
(0.1ms) BEGIN
Collection Load (1.0ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.6ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 47 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (0.5ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 47], ["created_at", "2018-06-18 13:56:14.825865"], ["updated_at", "2018-06-18 13:56:14.825865"]]
(1.4ms) COMMIT
Search Load (1.0ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "literary gifts"], ["LIMIT", 1]]
(0.4ms) BEGIN
Search Exists (0.7ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "literary gifts"], ["LIMIT", 1]]
SQL (0.7ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "literary gifts"], ["created_at", "2018-06-18 13:56:17.776368"], ["updated_at", "2018-06-18 13:56:17.776368"]]
(2.4ms) COMMIT
Item Exists (0.8ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 48], ["LIMIT", 1]]
(0.2ms) BEGIN
Collection Load (1.6ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.8ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 48 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (1.1ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 48], ["created_at", "2018-06-18 13:56:17.790424"], ["updated_at", "2018-06-18 13:56:17.790424"]]
(1.2ms) COMMIT
Search Load (0.7ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "book candles"], ["LIMIT", 1]]
(0.2ms) BEGIN
Search Exists (0.7ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "book candles"], ["LIMIT", 1]]
SQL (0.6ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "book candles"], ["created_at", "2018-06-18 13:56:20.872076"], ["updated_at", "2018-06-18 13:56:20.872076"]]
(1.4ms) COMMIT
Item Exists (0.6ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 49], ["LIMIT", 1]]
(0.1ms) BEGIN
Collection Load (0.6ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.7ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 49 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (0.8ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 49], ["created_at", "2018-06-18 13:56:20.883450"], ["updated_at", "2018-06-18 13:56:20.883450"]]
(2.3ms) COMMIT
Search Load (0.9ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "literary candles"], ["LIMIT", 1]]
(0.2ms) BEGIN
Search Exists (0.5ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "literary candles"], ["LIMIT", 1]]
SQL (0.8ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "literary candles"], ["created_at", "2018-06-18 13:56:22.523896"], ["updated_at", "2018-06-18 13:56:22.523896"]]
(1.4ms) COMMIT
Item Exists (0.7ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 50], ["LIMIT", 1]]
(0.2ms) BEGIN
Collection Load (0.7ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.9ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 50 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (0.9ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 50], ["created_at", "2018-06-18 13:56:22.536553"], ["updated_at", "2018-06-18 13:56:22.536553"]]
(2.2ms) COMMIT
Search Load (0.9ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "soy candle"], ["LIMIT", 1]]
Item Exists (0.7ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 18], ["LIMIT", 1]]
Search Load (0.6ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "8oz candles"], ["LIMIT", 1]]
(0.3ms) BEGIN
Search Exists (0.6ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "8oz candles"], ["LIMIT", 1]]
SQL (0.5ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "8oz candles"], ["created_at", "2018-06-18 13:56:25.455733"], ["updated_at", "2018-06-18 13:56:25.455733"]]
(2.4ms) COMMIT
Item Exists (0.8ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 51], ["LIMIT", 1]]
(0.2ms) BEGIN
Collection Load (0.7ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.6ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 51 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (1.0ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 51], ["created_at", "2018-06-18 13:56:25.468089"], ["updated_at", "2018-06-18 13:56:25.468089"]]
(1.2ms) COMMIT
Search Load (0.7ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "handmade soy candles"], ["LIMIT", 1]]
(0.2ms) BEGIN
Search Exists (0.5ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "handmade soy candles"], ["LIMIT", 1]]
SQL (0.5ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "handmade soy candles"], ["created_at", "2018-06-18 13:56:27.445609"], ["updated_at", "2018-06-18 13:56:27.445609"]]
(1.3ms) COMMIT
Item Exists (1.1ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 52], ["LIMIT", 1]]
(0.2ms) BEGIN
Collection Load (0.5ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.6ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 52 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (0.6ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 52], ["created_at", "2018-06-18 13:56:27.457050"], ["updated_at", "2018-06-18 13:56:27.457050"]]
(2.5ms) COMMIT
Search Load (0.7ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "bookish candle"], ["LIMIT", 1]]
Item Exists (0.6ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 13], ["LIMIT", 1]]
Search Load (0.5ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "bookish candles"], ["LIMIT", 1]]
(0.2ms) BEGIN
Search Exists (0.5ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "bookish candles"], ["LIMIT", 1]]
SQL (1.0ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "bookish candles"], ["created_at", "2018-06-18 13:56:29.102682"], ["updated_at", "2018-06-18 13:56:29.102682"]]
(1.6ms) COMMIT
Item Exists (0.8ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 53], ["LIMIT", 1]]
(0.3ms) BEGIN
Collection Load (0.5ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.5ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 53 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (0.6ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 53], ["created_at", "2018-06-18 13:56:29.114736"], ["updated_at", "2018-06-18 13:56:29.114736"]]
(2.1ms) COMMIT
Search Load (1.0ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "personalized gifts"], ["LIMIT", 1]]
(0.2ms) BEGIN
Search Exists (0.8ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "personalized gifts"], ["LIMIT", 1]]
SQL (0.8ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "personalized gifts"], ["created_at", "2018-06-18 13:56:30.446268"], ["updated_at", "2018-06-18 13:56:30.446268"]]
(1.5ms) COMMIT
Item Exists (1.0ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 54], ["LIMIT", 1]]
(0.2ms) BEGIN
Collection Load (0.9ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.7ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 54 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (0.8ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 54], ["created_at", "2018-06-18 13:56:30.459078"], ["updated_at", "2018-06-18 13:56:30.459078"]]
(2.2ms) COMMIT
Search Load (0.7ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "personalized gift"], ["LIMIT", 1]]
(0.3ms) BEGIN
Search Exists (0.5ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "personalized gift"], ["LIMIT", 1]]
SQL (0.6ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "personalized gift"], ["created_at", "2018-06-18 13:56:32.460438"], ["updated_at", "2018-06-18 13:56:32.460438"]]
(2.5ms) COMMIT
Item Exists (0.6ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 55], ["LIMIT", 1]]
(0.2ms) BEGIN
Collection Load (0.7ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.7ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 55 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (0.7ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 55], ["created_at", "2018-06-18 13:56:32.474614"], ["updated_at", "2018-06-18 13:56:32.474614"]]
(1.1ms) COMMIT
Search Load (0.8ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "book smell"], ["LIMIT", 1]]
(0.5ms) BEGIN
Search Exists (0.8ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "book smell"], ["LIMIT", 1]]
SQL (0.7ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "book smell"], ["created_at", "2018-06-18 13:56:34.573441"], ["updated_at", "2018-06-18 13:56:34.573441"]]
(1.3ms) COMMIT
Item Exists (0.6ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 56], ["LIMIT", 1]]
(0.1ms) BEGIN
Collection Load (1.4ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.6ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 56 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (0.6ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 56], ["created_at", "2018-06-18 13:56:34.585728"], ["updated_at", "2018-06-18 13:56:34.585728"]]
(2.5ms) COMMIT
Redirected to http://localhost:3000/collections/1
Completed 302 Found in 24422ms (ActiveRecord: 153.5ms)
The amount of items I'm inserting varies but even between many different examples, PG always takes longer, even though when looking at those two logs I posted, it seems like SQLite3 is taking longer per transaction.
Is this normal or is there something I can do to optimize it?
Thanks!
Looks like ActiveRecord is responding pretty quickly for both databases:
Sqlite: ActiveRecord: 12.3ms
Postgres: ActiveRecord: 153.5ms
While Postgres is certainly higher, I would think both of those response times would be acceptable, and that they would vary slightly each time you hit that action.
You do, however, have some sort of redirect taking place 302 Redirected to http://localhost:3000/collections/1 that seems to be adding a bunch of time to the request.
You might try making sure that there are no scripts on that page that are gumming up the works. Also, you might make sure that the indexes have been applied to your Postgres database, and also make sure your collections page doesn't have any n+1 queries.
Hard to say more with the limited information given in the question,

Rails Ajax redirect, doesn`t change the view

Hi I have a character_form with js: true
This are my controller actions:
def new
#user = User.find(params[:user_id])
#character = Character.new
#clan = Clan.where(name: params[:clan]).take || Clan.where(name: "Feniks").take
#families = #clan.families
respond_to do |format|
format.js
format.html
end
end
def create
#user = User.find(params[:user_id])
#character = #user.characters.new(character_params)
if #character.save
redirect_to current_user
else
#clan = Clan.where(name: params[:character][:clan]).take
#families = #clan.families
render :new
end
end
And user#show action:
def show
#user = User.find(params[:id])
#characters = #user.characters.all.order(:family, :name)
end
After I submit the character_form the server shows:
Started POST "/users/1/characters" for 127.0.0.1 at 2015-11-17 01:55:20 -0400
Processing by CharactersController#create as JS
Parameters: {"utf8"=>"✓", "character"=>{"name"=>"Q mlak", "clan"=>"Feniks", "family"=>"Agasha", "desc"=>"alalalal"}, "commit"=>"Zapisz", "user_id"=>"1"}
User Load (5.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
(0.6ms) BEGIN
SQL (4.4ms) INSERT INTO "characters" ("name", "clan", "desc", "family", "user_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["name", "Q mlak"], ["clan", "Feniks"], ["desc", "alalalal"], ["family", "Agasha"], ["user_id", 1], ["created_at", "2015-11-17 05:55:20.778436"], ["updated_at", "2015-11-17 05:55:20.778436"]]
(30.4ms) COMMIT
Redirected to http://localhost:3000/users/1
Completed 302 Found in 52ms (ActiveRecord: 40.7ms)
Started GET "/users/1" for 127.0.0.1 at 2015-11-17 01:55:20 -0400
Processing by UsersController#show as JS
Parameters: {"id"=>"1"}
User Load (2.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
(0.3ms) SELECT COUNT(*) FROM "characters" WHERE "characters"."user_id" = $1 [["user_id", 1]]
Character Load (0.2ms) SELECT "characters".* FROM "characters" WHERE "characters"."user_id" = $1 ORDER BY "characters"."family" ASC, "characters"."name" ASC [["user_id", 1]]
Rendered users/show.html.erb within layouts/application (8.3ms)
Rendered layouts/_header.html.erb (4.1ms)
Rendered layouts/_gretel.html.erb (0.9ms)
Rendered layouts/_footer.html.erb (0.4ms)
Completed 200 OK in 423ms (Views: 415.9ms | ActiveRecord: 3.1ms)
I don`t have create.js.erb nor show.js.erb files.
My problem is that the view in the browser doesn't fallow the server. I know that ajax fakes the screen. My goal is to redirect to current_user path as html after form is submitted.

I can't fetch any rows from a Polymorphic association

I've set up 2 polymorphic associations on a table, I have no problem adding to the table but I can't seem to retrieve the added information.
Here's what I'm doing:
Post
belongs_to :posted, polymorphic: true
belongs_to :received, polymorphic: true
User
has_many :posted_posts, class_name: 'Post', as: :posted
has_many :received_posts, class_name: 'Post', as: :received
Group
has_many :posted_posts, class_name: 'Post', as: :posted
has_many :received_posts, class_name: 'Post', as: :received
users_controller.rb
def post
authorize #user
#post = Post.new(post_params)
#post.received = #user
#post.posted = #current_user
if #post.save
respond_to do |format|
format.html {redirect_to root_url}
format.js
end
else
respond_to do |format|
format.html {redirect_to root_url}
format.js
end
end
end
Post seems to be fine, but I should be able to retrieve the information by using
<% #user.received_posts do |post| %>
<%= post.content %>
<% end %>
<% #user.posted_posts do |post| %>
<%= post.content %>
<% end %>
But neither of these work. What am I missing? It's not bringing up an error. In fact, the logs aren't showing anything.. it's like it's being ignored. Do I need a method somewhere that does some lifting? I though the rest is handled by rails..
Any help would be appreciated.
UPDATE - Logs
Started GET "/!/David" for 127.0.0.1 at 2014-08-18 12:02:32 +0100
Processing by UsersController#show as HTML
Parameters: {"username"=>"David"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 ORDER BY "users"."id" ASC LIMIT 1
User Load (0.2ms) SELECT "users".* FROM "users" WHERE (username == 'David') LIMIT 1
(0.2ms) SELECT COUNT(*) FROM "follows" WHERE "follows"."followable_id" = ? AND "follows"."followable_type" = ? AND "follows"."blocked" = 'f' [["followable_id", 3], ["followable_type", "User"]]
(0.2ms) SELECT COUNT(*) FROM "follows" WHERE "follows"."blocked" = 'f' AND "follows"."follower_id" = 2 AND "follows"."follower_type" = 'User' AND "follows"."followable_id" = 3 AND "follows"."followable_type" = 'User'
Rendered users/_links.html.erb (1.2ms)
Rendered users/show.html.erb within layouts/application (7.8ms)
Rendered layouts/_app_sidebar.html.erb (0.8ms)
Mailboxer::Conversation Load (0.6ms) SELECT DISTINCT "mailboxer_conversations".* FROM "mailboxer_conversations" INNER JOIN "mailboxer_notifications" ON "mailboxer_notifications"."conversation_id" = "mailboxer_conversations"."id" AND "mailboxer_notifications"."type" IN ('Mailboxer::Message') INNER JOIN "mailboxer_receipts" ON "mailboxer_receipts"."notification_id" = "mailboxer_notifications"."id" WHERE "mailboxer_notifications"."type" = 'Mailboxer::Message' AND "mailboxer_receipts"."receiver_id" = 2 AND "mailboxer_receipts"."receiver_type" = 'User' ORDER BY mailboxer_conversations.updated_at DESC
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 37]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 44]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 45]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 46]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 43]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 42]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 41]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 40]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.3ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 39]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.3ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 38]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.3ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 36]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.4ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 35]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.3ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 34]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.3ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 33]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.4ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 32]]
CACHE (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 31]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.3ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 30]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 29]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 28]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 27]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 26]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 25]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 24]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.3ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 23]]
CACHE (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.3ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 22]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.3ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 21]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 20]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 19]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 18]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 17]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 16]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 15]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.3ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 14]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 13]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 12]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 11]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 10]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 9]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 8]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 7]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 6]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 5]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.3ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 4]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 3]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 2]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Mailboxer::Message Load (0.2ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ? ORDER BY created_at DESC LIMIT 1 [["conversation_id", 1]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Rendered mailboxer/conversations/_conversation.html.erb (155.4ms)
Rendered layouts/_app_header.html.erb (159.5ms)
Rendered layouts/_messages.html.erb (0.1ms)
Completed 200 OK in 223ms (Views: 206.2ms | ActiveRecord: 13.5ms)
Turned out that you missed .each:
<% #user.posted_posts.each do |post| %>

No error is shown but return result is empty in index

i'm trying to create a Result which belongs to Generator. In order to create the Result, I did the code in Generator show.html.erb and render the form ( of Result ) in the show.html.erb of Generator. However, Result method is not called when i click the submt button. How can i solve this ? There are no errors shown either so i do not know where goes wrong. When i type Result.all in console, no records were in the db as well. I followed the way of associating 2nd object with the 1st but still can't get them right. Please help me .
Log ( no idea why it's so long. Definately there's something gone wrong)
Started GET "/users/1/generators/new" for 127.0.0.1 at 2013-12-13 23:36:51 +0800
Processing by GeneratorsController#new as HTML
Parameters: {"user_id"=>"1"}
[1m[35mUser Load (2.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
[1m[36mCACHE (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m [["id", 1]]
Rendered generators/_form.html.erb (77.0ms)
Rendered generators/new.html.erb within layouts/application (82.0ms)
[1m[35mCACHE (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
[1m[36mCACHE (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m [["id", 1]]
[1m[35mCACHE (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
[1m[36mCACHE (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m [["id", 1]]
[1m[35mCACHE (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
Completed 200 OK in 256ms (Views: 179.0ms | ActiveRecord: 15.0ms)
Started POST "/users/1/generators" for 127.0.0.1 at 2013-12-13 23:36:56 +0800
Processing by GeneratorsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"SBzLTWzzkziEGPDL7BZFnxdKuVeBJXQXUpKta3k5erQ=", "choice"=>"Randomly", "generator"=>{"primer_length"=>"10"}, "no_A"=>"", "no_T"=>"", "no_G"=>"", "no_C"=>"", "user_seq"=>"", "result_choice"=>"Yes", "commit"=>"Generate", "user_id"=>"1"}
[1m[36mUser Load (2.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m [["id", 1]]
[1m[35mCACHE (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
[1m[36m (2.0ms)[0m [1mBEGIN[0m
[1m[35mSQL (3.0ms)[0m INSERT INTO "generators" ("choice", "created_at", "f_primer", "melting_temp", "primer_length", "r_primer", "random_primer_generated", "result_choice", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "id" [["choice", "Randomly"], ["created_at", Fri, 13 Dec 2013 23:36:56 MYT +08:00], ["f_primer", "GTGCTAAAAT"], ["melting_temp", 26.0], ["primer_length", 10], ["r_primer", "ATTTTAGCAC"], ["random_primer_generated", "GTGCTAAAAT"], ["result_choice", "Yes"], ["updated_at", Fri, 13 Dec 2013 23:36:56 MYT +08:00], ["user_id", 1]]
[1m[36m (103.0ms)[0m [1mCOMMIT[0m
Redirected to http://localhost:3000/users/1/generators/5
Completed 302 Found in 136ms (ActiveRecord: 110.0ms)
Started GET "/users/1/generators/5" for 127.0.0.1 at 2013-12-13 23:36:56 +0800
Processing by GeneratorsController#show as HTML
Parameters: {"user_id"=>"1", "id"=>"5"}
[1m[35mUser Load (2.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
[1m[36mGenerator Load (2.0ms)[0m [1mSELECT "generators".* FROM "generators" WHERE "generators"."id" = $1 LIMIT 1[0m [["id", "5"]]
[1m[35mResult Load (2.0ms)[0m SELECT "results".* FROM "results" WHERE "results"."generator_id" = $1 ORDER BY "results"."id" ASC LIMIT 1 [["generator_id", 5]]
[1m[36mCACHE (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m [["id", 1]]
Rendered results/_form.html.erb (79.0ms)
Rendered generators/show.html.erb within layouts/application (85.0ms)
[1m[35mCACHE (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
[1m[36mCACHE (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m [["id", 1]]
[1m[35mCACHE (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
[1m[36mCACHE (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m [["id", 1]]
[1m[35mCACHE (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
Completed 200 OK in 140ms (Views: 119.0ms | ActiveRecord: 14.0ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2013-12-13 23:36:57 +0800
Started GET "/assets/generators.css?body=1" for 127.0.0.1 at 2013-12-13 23:36:57 +0800
Started GET "/assets/identities.css?body=1" for 127.0.0.1 at 2013-12-13 23:36:57 +0800
Started GET "/assets/results.css?body=1" for 127.0.0.1 at 2013-12-13 23:36:57 +0800
Started GET "/assets/scaffolds.css?body=1" for 127.0.0.1 at 2013-12-13 23:36:57 +0800
Started GET "/assets/sessions.css?body=1" for 127.0.0.1 at 2013-12-13 23:36:57 +0800
Started GET "/assets/welcome.css?body=1" for 127.0.0.1 at 2013-12-13 23:36:57 +0800
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-12-13 23:36:57 +0800
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-12-13 23:36:57 +0800
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2013-12-13 23:36:57 +0800
Started GET "/assets/generators.js?body=1" for 127.0.0.1 at 2013-12-13 23:36:57 +0800
Started GET "/assets/identities.js?body=1" for 127.0.0.1 at 2013-12-13 23:36:57 +0800
Started GET "/assets/registrations.js?body=1" for 127.0.0.1 at 2013-12-13 23:36:57 +0800
Started GET "/assets/results.js?body=1" for 127.0.0.1 at 2013-12-13 23:36:58 +0800
Started GET "/assets/sessions.js?body=1" for 127.0.0.1 at 2013-12-13 23:36:58 +0800
Started GET "/assets/welcome.js?body=1" for 127.0.0.1 at 2013-12-13 23:36:58 +0800
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-12-13 23:36:58 +0800
Started PUT "/users/1/generators/5?generator_id=5" for 127.0.0.1 at 2013-12-13 23:37:08 +0800
Processing by GeneratorsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"SBzLTWzzkziEGPDL7BZFnxdKuVeBJXQXUpKta3k5erQ=", "ncbi_ref_seq"=>"", "genome_seq"=>"TGATGAACATCATGATGAGGTGATGACATCACATCATTGACTGATGCATCATGATG", "commit"=>"Analyze", "generator_id"=>"5", "user_id"=>"1", "id"=>"5"}
[1m[36mUser Load (2.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m [["id", 1]]
[1m[35mGenerator Load (2.0ms)[0m SELECT "generators".* FROM "generators" WHERE "generators"."id" = $1 LIMIT 1 [["id", "5"]]
[1m[36m (2.0ms)[0m [1mBEGIN[0m
[1m[35m (2.0ms)[0m COMMIT
[1m[36m (1.0ms)[0m [1mBEGIN[0m
[1m[35m (2.0ms)[0m COMMIT
[1m[36mCACHE (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m [["id", 1]]
Redirected to http://localhost:3000/users/1/generators.5?id=5
Completed 302 Found in 27ms (ActiveRecord: 11.0ms)
Started GET "/users/1/generators.5?id=5" for 127.0.0.1 at 2013-12-13 23:37:08 +0800
Processing by GeneratorsController#index as
Parameters: {"id"=>"5", "user_id"=>"1"}
[1m[35mUser Load (2.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
[1m[36mCACHE (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m [["id", 1]]
[1m[35mGenerator Load (2.0ms)[0m SELECT "generators".* FROM "generators" WHERE "generators"."user_id" = $1 [["user_id", 1]]
[1m[36mResult Load (1.0ms)[0m [1mSELECT "results".* FROM "results" WHERE "results"."generator_id" = $1 ORDER BY "results"."id" ASC LIMIT 1[0m [["generator_id", 1]]
[1m[35mCACHE (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
[1m[36mCACHE (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m [["id", 1]]
[1m[35mResult Load (2.0ms)[0m SELECT "results".* FROM "results" WHERE "results"."generator_id" = $1 ORDER BY "results"."id" ASC LIMIT 1 [["generator_id", 2]]
[1m[36mCACHE (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m [["id", 1]]
[1m[35mCACHE (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
[1m[36mResult Load (2.0ms)[0m [1mSELECT "results".* FROM "results" WHERE "results"."generator_id" = $1 ORDER BY "results"."id" ASC LIMIT 1[0m [["generator_id", 3]]
[1m[35mCACHE (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
[1m[36mCACHE (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m [["id", 1]]
[1m[35mResult Load (2.0ms)[0m SELECT "results".* FROM "results" WHERE "results"."generator_id" = $1 ORDER BY "results"."id" ASC LIMIT 1 [["generator_id", 4]]
[1m[36mCACHE (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m [["id", 1]]
[1m[35mCACHE (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
[1m[36mResult Load (2.0ms)[0m [1mSELECT "results".* FROM "results" WHERE "results"."generator_id" = $1 ORDER BY "results"."id" ASC LIMIT 1[0m [["generator_id", 5]]
[1m[35mCACHE (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
[1m[36mCACHE (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m [["id", 1]]
Rendered generators/index.html.erb within layouts/application (61.0ms)
[1m[35mCACHE (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
[1m[36mCACHE (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m [["id", 1]]
[1m[35mCACHE (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
[1m[36mCACHE (0.0ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m [["id", 1]]
[1m[35mCACHE (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
Completed 200 OK in 128ms (Views: 111.0ms | ActiveRecord: 13.0ms)
Generator controller
def show
end
# GET /generators/new
def new
#generator=Generator.new(params[:generator])
end
def index
##generators = current_user.generators
##generators = #generators.order("created_at DESC")
end
def create
#generator = current_user.generators.build(generator_params)
#generator.choice = params[:choice]
if params[:choice] == 'Randomly'
#generator.random_generate(generator_params)
elsif params[:choice] == 'Specified ATGC'
#generator.specified_ATGC(params[:no_A],params[:no_T],params[:no_G],params[:no_C])
elsif params[:choice] == 'Seating'
#generator.seating(params[:user_seq])
end
#generator.result_choice=params[:result_choice]
#generator.save
respond_to do |format|
if #generator.result_choice == 'Yes'
format.html { redirect_to(:action =>"show",:id =>#generator.id )}
else
format.html { redirect_to(user_generators_path(#generator,:user_id => current_user.id,:generator_id=>#generator.id) ) }
end
end
end
# PATCH/PUT /generators/1
# PATCH/PUT /generators/1.json
def update
respond_to do |format|
if #generator.update(params[:generator])
#generator.save
format.html { redirect_to(user_generators_path(#generator,:user_id => current_user.id,:id=>#generator.id) ) }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: #generator.errors, status: :unprocessable_entity }
end
end
end
Result controller
def new
end
# GET /results/1/edit
# POST /results
# POST /results.json TGATGAACATCATGATGAGGTGATGACATCACATCATTGACTGATGCATCATGATG
def create
#result = #generator.build_result(result_params)
#generator=#result.generate_result(result_params)
#generator.result.save
redirect_to user_generators_path
end
Result Form that was rendered in Generator show.html.erb
<%= form_for(#generator.build_result(params[:result]),:url =>user_generator_path(#generator,:user_id => current_user.id, :generator_id => #generator.id),:html =>{:method=>:put}) do |f| %>
<script>
$(document).ready(function(){
$("#accession_number").click(function(){
$("#FASTA").hide();
$("#highlight").hide();
})
$("#FASTA").click(function(){
$("#accession_number").hide();
$("#highlight").hide();
})
$("#reset").click(function(){
$("#accession_number").show();
$("#FASTA").show();
$("#highlight").show();
})
});
</script>
<font size ="6">*** <u>Choose ONE of the input methods</u> *** </font>
<p id="accession_number">
<label><strong><font size ="3">NCBI accession number:</font></strong></label><br />
<%= text_field_tag(:ncbi_ref_seq,nil,placeholder: 'Accession Number')%>
</p>
<p id="highlight"><font size ="5">
OR
</font></p>
<p id="FASTA">
<strong><font size ="3">Paste your sequence here: ( FASTA format ) :</font></strong>
<%= text_area_tag(:genome_seq,nil,size: "50x10",placeholder: 'Input your sequence here')%>
</p>
<input type="reset" value="Reset" id="reset">
<%= submit_tag 'Analyze' %>
<% end %>
Form for Generator ( i need to use tag else if i use f.button , i get empty result)
<html>
<script>
$(document).ready(function() {
var total = 0;
$.each($(':input'), function(){
total += parseInt($(this).val(), 10); //use radix 10 to ensure correct parseInt val
});
$("span").text(i);
});
</script>
<body >
<%= form_for(#generator, :url => user_generators_path(:user_id => current_user.id, :id => #generator.id)) do |f| %>
<% if #generator.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#generator.errors.count, "error") %> prohibited this generator from being saved:</h2>
<ul>
<% #generator.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% else %>
<fieldset class ="primer">
<legend><strong>Method Use :</strong></legend><br>
<h3 align="left"><font size ="5"><b>Step 1: <u>Choose only ONE of the methods</u></font></b></h3>
<table class="p_gen">
<thead>
<tr>
<th class="method1"><label>Randomly</label><br />
<%= radio_button_tag(:choice, 'Randomly',checked:true )%>
<p> ( Generate a primer randomly )</p></th>
<th class="method2"><label>Specified ATGC</label><br />
<%= radio_button_tag(:choice,'Specified ATGC')%>
<p> ( Generate a primer with number of A,T,G and C )</p></th>
<th class="method3"><label>Seating</label><br />
<%= radio_button_tag(:choice,'Seating')%>
<p> ( Generate a primer according to your preference )</p></th>
</tr>
</thead>
<tbody>
<tr>
<td class="method1">
<p> Input length of the primer you want : </p>
<label>Primer Length :</label>
<%= f.number_field(:primer_length , min: 6 , max: 35)%>
</td>
<td class="method2">
<p>Input the number of each base the primer should have</p>
<label>Number of A :</label>
<%= number_field_tag :no_A,nil, :min=>0, :max=>35 %><br />
<label>Number of T :</label>
<%= number_field_tag :no_T,nil, :min=>0, :max=>35 %><br />
<label>Number of G :</label>
<%= number_field_tag :no_G,nil, :min=>0, :max=>35 %><br />
<label>Number of C :</label>
<%= number_field_tag :no_C,nil, :min=>0, :max=>35 %><br />
Total bases:<span></span>
</td>
<td class="method3">
<p> Input your preference sequence (only IUPAC nucleotide).</p>
<p><b><u>IUPAC Nucleotide :</u></b></p>
<p>A,T,G,C,R,Y,S,W,K,M,B,D,H,V,N </p>
Example: <br />
Preference primer = TAGGCT<b>N</b>TTA<b>N</b>GAC<b>N</b> <br />
N = Any base ( A/ T / G / C) <br /><br />
<label>Desired sequence :</label><br>
<%= text_field_tag(:user_seq,nil,:maxlength => 35)%>
</td>
</tr>
</tbody>
</table>
</fieldset>
<br>
<fieldset class ="sample">
<h4><font size="5"><b>Step 2: <u>Choose 'Yes' if you want to input reference sequence for Binding-time analysis </font></u></b></h4>
<legend><strong>Do you have NCBI data to extract / FASTA file to input?</strong></legend><br>
<label>Yes</label>
<%= radio_button_tag(:result_choice,'Yes')%>
<label>No</label>
<%= radio_button_tag(:result_choice,'No')%>
<br>
</fieldset>
<br><div class = "button">
<%=f.submit("Generate", :class => "Gbutton_class") %>
</div>
<%end %>
<%end%>
</body>
</html>
routes.rb
Project::Application.routes.draw do
get "/signout" => "sessions#destroy", :as => :signout
root :to => 'welcome#index'
get '/auth/:provider/callback' => 'sessions#create'
post '/auth/identity/callback' => 'sessions#create'
resources :users do
resources :generators
resources :results
end
resources :identities
I'm not entirely clear why there are two Generator forms (perhaps I'm missing something), but in some places you're using the singular user: user_generators_path where in others you're using users_generators_path (note the plural users). Check which is correct via rake routes, and fix any incorrect entries.

Resources