rails hiredis undefined symbol - ruby-on-rails

I want to build a shopping cart for my website. I've installed redis/hiredis but when I start the server, if I go on a page where the shopping cart whould show a value (current items in cart), or if I want to go on the shopping cart page, the server crashes giving the following information:
Started GET "/cart" for 127.0.0.1 at 2015-05-19 13:43:33 +0300
ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by CartsController#show as HTML
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
/home/svuser/.rvm/rubies/ruby-2.2.0/bin/ruby: symbol lookup error: /home/svuser/.rvm/gems/ruby-2.2.0/gems/hiredis-0.4.5/lib/hiredis/ext/hiredis_ext.so: undefined symbol: rb_thread_select
In my index page, I create a link to the shopping cart using the following instructions :
<%if signed_in?%>
<li>
<%= link_to cart_path do%>
<i class="fi-shopping-cart"></i>
My Cart
<%end%>
Is there any way to work around this issue ? I am still new to rails and I couldn't figure it out on my own.

I faced a similar problem. In my case, I use Ruby 2.2.2p95 and old version gem hiredis - '0.4.5'. It uses method rb_thread_select, which was removed in Ruby 2.2
So bundle update hiredis helps me.

Related

link_to nested resource route can't find ID

The link_to in my user name is creating an error and I don't know why.
Error:
Couldn't find StripeAccount without an ID
Controller:
this is inside a separate controller from the StripeAccount controller
def settings
#user = current_user.id
#stripe_account = StripeAccount.find(params[:stripe_account_id])
end
I have tried "#stripe_account = StripeAccount.find(params[:id])" with the same error
View:
<%= link_to user_stripe_account_path(#user, #stripe_account) %>
I have tried using #stripe_account.id, etc.
Models:
stripe_account::
belongs_to :user, optional: true
user::
has_one :stripe_account
Routes:
resources :users do
resources :stripe_accounts
end
Error when i try loading the /settings page:
Here's the CMD from when I use: #stripe_account = StripeAccount.find(params[:stripe_account_id])
app/controllers/dashboard_controller.rb:18:in `settings'
Started GET "/settings" for 127.0.0.1 at 2018-11-17 06:27:04 -0500
Processing by DashboardController#settings as HTML
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 2], ["LIMIT", 1]]
↳ app/controllers/dashboard_controller.rb:17
Completed 404 Not Found in 3ms (ActiveRecord: 0.3ms)
ActiveRecord::RecordNotFound (Couldn't find StripeAccount without an ID):
app/controllers/dashboard_controller.rb:18:in `settings'
When i use #stripe_account = StripeAccount.find(params[:id])
ActiveRecord::RecordNotFound (Couldn't find StripeAccount without an ID):
app/controllers/dashboard_controller.rb:18:in `settings'
Started GET "/settings" for 127.0.0.1 at 2018-11-17 06:28:21 -0500
Processing by DashboardController#settings as HTML
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 2], ["LIMIT", 1]]
↳ app/controllers/dashboard_controller.rb:17
Completed 404 Not Found in 3ms (ActiveRecord: 0.3ms)
ActiveRecord::RecordNotFound (Couldn't find StripeAccount without an ID):
app/controllers/dashboard_controller.rb:18:in `settings'
What am i doing incorrectly?
The only issue i can think of that may be happening is rails/ruby is finding the API ID from stripe_account, which contains a bunch of information from stripe... if so, is there a way i can specifically state using the ID from the table?
You should be able to do #stripe_account = current_user.stripe_account if you wan't to set the variable to the current_user's stripe account (you have no id param on the request). And I recommend you to use #user = current_user or #user_id = current_user.id since it's confusing to read a variable named #user that has an integer value.
When you define "StripeAccount belongs_to User", by default (it's the convention) ActiveRecord looks for a user_id column on stripe_accounts table.
I'd recommend you to read this https://guides.rubyonrails.org/association_basics.html. It explains all types of associations and you can configure your associations even if they are not conventional (different class names, no _id column, etc).
After many attempts, i got one way to work. I'm not sure how efficient this is and i will explore more options.
This ended up working how i wanted to:
#stripe_account = StripeAccount.find_by(params[:id])
The key was using ".find_by" and not ".find". This allows the link_to to operate and goes to the right location.

Rails Fragment Caching doesn't work

I was trying to add fragment caching to speed up website performance.
Now, I tested it in development mode, so I change this
#environments/developments.rb
config.action_controller.perform_caching = true
And in erb
<% #projects.each do |project| %>
<% cache project do %>
<%= link_to "#{project.name}", category_project_path(#category, project) %>
<br>
<% end %>
<% end %>
However, it seems not work. Every time I refresh the page, it showed query again in terminal.
I thought it would only query once in first time, or I've misunderstood the concept of cache?
Processing by CategoriesController#show as HTML
Parameters: {"id"=>"3306"}
Category Load (0.4ms) SELECT "categories".* FROM "categories" WHERE "categories"."id" = $1 LIMIT 1 [["id", 3306]]
Project Load (0.5ms) SELECT "projects".* FROM "projects" WHERE "projects"."category_id" IN (3306)
(0.4ms) SELECT DISTINCT COUNT(DISTINCT "projects"."id") FROM "projects" WHERE "projects"."category_id" = $1 [["category_id", 3306]]
Project Load (1.0ms) SELECT DISTINCT "projects".* FROM "projects" WHERE "projects"."category_id" = $1 LIMIT 10 OFFSET 0 [["category_id", 3306]]
Cache digest for app/views/categories/show.html.erb: 9b54e2d9c7ce230e3f6a333f00d549da
Read fragment views/projects/3670-20160715055333331671000/9b54e2d9c7ce230e3f6a333f00d549da (0.2ms)
Cache digest for app/views/categories/show.html.erb: 9b54e2d9c7ce230e3f6a333f00d549da
Read fragment views/projects/3677-20160715055334439274000/9b54e2d9c7ce230e3f6a333f00d549da (0.2ms)
Cache digest for app/views/categories/show.html.erb: 9b54e2d9c7ce230e3f6a333f00d549da
Read fragment views/projects/3678-20160715055334446172000/9b54e2d9c7ce230e3f6a333f00d549da (0.2ms)
Cache digest for app/views/categories/show.html.erb: 9b54e2d9c7ce230e3f6a333f00d549da
Read fragment views/projects/3689-20160715055334536421000/9b54e2d9c7ce230e3f6a333f00d549da (0.1ms)
Rendered categories/show.html.erb within layouts/application (8.7ms)
Completed 200 OK in 31ms (Views: 26.0ms | ActiveRecord: 2.3ms)
According to your logs it looks like data is product is populated from the cache and no query is fired for product.
views/projects/3670-20160715055333331671000/9b54e2d9c7ce230e3f6a333f00d549da
The number in the middle is the product_id followed by the timestamp value in the updated_at attribute of the product record. Rails uses the timestamp value to make sure it is not serving stale data. If the value of updated_at has changed, a new key will be generated(fires query to database). Then Rails will write a new cache to that key, and the old cache written to the old key will never be used again.
Hope this help!

rails remote call internal server error 500 in book agile web dev rails 4 - chapter 11

I'm new to rails (my 5th week) and currently I learn with the book "agile web dev with rails 4". I just finished chapter 11 and to my own amusement, I planed to add a remote call to destroy all quantity from a item in the cart. Well, the problem is, I get a internal error message 500.
I added the code "remote: true" in file line_items/_line_item.html.erb
...
...
<%= button_to 'Remove Item', line_item, method: :delete, remote: true %>
And changed the redirect for html to store_path and added a format.js in the line_items_controller.rb
I created a destroy.js.erb file and added the code
$('#cartContainer').html('<%= escape_javascript render(#cart) %>');
I guess the #cart is wrong. But I just can't figured out and probably i lost totally the overview over the hole project :)
Here the server log:
Started DELETE "/line_items/105" for 127.0.0.1 at 2014-08-07 12:44:15 +0200
Processing by LineItemsController#destroy as JS
Parameters: {"authenticity_token"=>"ofobuV7Pk1avFiV6KSQ7NHnc/J77PJWWejsKVyg3YLQ=", "id"=>"105"}
LineItem Load (0.1ms) SELECT "line_items".* FROM "line_items" WHERE "line_items"."id" = ? LIMIT 1 [["id", 105]]
CACHE (0.0ms) SELECT "line_items".* FROM "line_items" WHERE "line_items"."id" = ? LIMIT 1 [["id", "105"]]
(0.1ms) begin transaction
SQL (0.4ms) DELETE FROM "line_items" WHERE "line_items"."id" = ? [["id", 105]]
(1.6ms) commit transaction
Rendered line_items/destroy.js.erb (0.9ms)
Completed 500 Internal Server Error in 8ms
ActionView::Template::Error ('nil' is not an ActiveModel-compatible object. It must implement :to_partial_path.):
1: // reload cart after adding item
2: $('#cartContainer').html('<%= escape_javascript render(#cart) %>');
app/views/line_items/destroy.js.erb:2:in `_app_views_line_items_destroy_js_erb__1371414078062466935_70243559055940'
app/controllers/line_items_controller.rb:81:in `destroy'
You are getting this error because #cart is nil. In your controllers destroy method initialise #cart
def destroy
#cart = current_cart
// other logic
end

rails3-bootstrap-devise-cancan gmaps4raills map display issue

Sorry I am a bit of a Rails newbie but have been trying to get gmaps4rails to work with twitter bootstrap and have hit a bit of a dead end. Nothing seems to resolve it or point in the right direction after hours of Googling.I have gone through all the steps before with an un-bootstrapped rails app and it worked, but for some reason the map wont display in the TBS version.
Just to note I used the rails3-bootstrap-devise-cancan template in case there are any known issues with that.
I have included this stylesheet link at the top of my view:
<head>
<% content_for :head do %>
<%= stylesheet_link_tag :gmaps4rails -%>
<% end %>
</head>
…..
<%= gmaps4rails(#json) %>
In the head of the application.html..erb
<%= yield :head %>
In the controllers index action:
#json = Outlet.all.to_gmaps4rails
and in the model:
acts_as_gmappable :position => :location
def gmaps4rails_address
address
end
gmaps4rails.css is in the stylesheets folder so should be accessible.
Gemfile
gem 'gmaps4rails'
gem 'twitter-bootstrap-rails'
I also added this gem
gem 'thin'
Because i was getting another error about the content-length but I'm pretty sure it was unrelated to the gmaps problem (maps don't show up before or after installing this gem)
Also, when I load the app in firefox I can see from the activity in the bottom left of the screen that it appears to be connecting successfully to the Google Maps API and no errors are displayed in the terminal.
This is the terminal output.
Started GET "/outlets" for 127.0.0.1 at 2013-01-17 21:26:24 +0000
Processing by OutletsController#index as HTML
Outlet Load (0.2ms) SELECT "outlets".* FROM "outlets"
CACHE (0.0ms) SELECT "outlets".* FROM "outlets"
Rendered /Users/mikemccann/.rvm/gems/ruby-1.9.3-p362#myapp/gems/gmaps4rails-1.5.6/app/views/gmaps4rails/_gmaps4rails.html.erb (1.1ms)
Rendered outlets/index.html.erb within layouts/application (4.2ms)
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
(0.1ms) SELECT COUNT(*) FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = 1 AND (((roles.name = 'admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))
Rendered layouts/_navigation.html.erb (188.2ms)
Rendered layouts/_messages.html.erb (0.1ms)
Completed 200 OK in 212ms (Views: 208.7ms | ActiveRecord: 1.6ms)
Really stumped by this one so any help is greatly appreciated!!!
Mike
Are you explicitly giving your map container div a height? What happens when you look at the HTML in the developer console? Is anything Gmaps related showing in the map container div?

Ajax Delete links log out current_user

The title pretty much explains it. I'm having an odd situation where views that allow users to delete notifications using Ajax cause the current_user to be logged out. I don't even know where to begin debugging this...
Here's the controller
class NotificationsController < ApplicationController
def destroy
#notification = Notification.find(params[:id])
#notification.destroy
respond_to do |format|
format.js
end
end
end
This is the entire controller, nothing is abridged. The notifications are generated by the system, so the only action a user can take is to "dismiss" (ie. delete) them.
I also tried this using the newer respond_with syntax and had the same effect.
I'm using Devise, and Rails 3.0.9. Any idea what could be going on -- or suggestions on how to debug??
-- EDIT 1 --
Routes.rb
resources :notifications, :only => [:destroy]
Delete link
%span.delete= link_to( 'dismiss', notification_path(notification), :method => :delete, :remote => true )
-- EDIT 2 --
Well, I noticed something new in the logs -- see **** below.
Started DELETE "/notifications/10" for 127.0.0.1 at 2011-06-21 21:47:15 -0500
Processing by NotificationsController#destroy as JS
Parameters: {"id"=>"10"}
SQL (0.4ms) SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
SQL (0.3ms) SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Slug Load (0.4ms) SELECT "slugs".* FROM "slugs" WHERE ("slugs".sluggable_id = 1 AND "slugs".sluggable_type = 'User') ORDER BY id DESC LIMIT 1
****AREL (0.3ms) UPDATE "users" SET "remember_token" = NULL, "remember_created_at" = NULL, "updated_at" = '2011-06-22 02:47:15.913839', "preferences" = '---
:email_notifications: ''true''
' WHERE "users"."id" = 1
Notification Load (0.2ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."id" = 10 LIMIT 1
User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
AREL (0.3ms) UPDATE "users" SET "notifications_count" = COALESCE("notifications_count", 0) - 1 WHERE "users"."id" = 1
AREL (0.1ms) DELETE FROM "notifications" WHERE "notifications"."id" = 10
Rendered notifications/destroy.js.erb (0.7ms)
Completed 200 OK in 6416ms (Views: 9.6ms | ActiveRecord: 4.1ms)
So, there it is, it looks like part of the users table is getting set to null, particularly the remember_token which I suspect is triggering Devise to end the session, or maybe this is done by Devise after the session is destroyed. But how do I track that down?
The only thing I can think of that causes notifications to interact with Users is there's a counter_cache on Users for notifications_count.
I appreciate thoughts and suggestions on how to debug!
-- EDIT 3 --
After digging with ruby-debug it looks like the issue is related to Devise and changes to the rails.js script. See:
https://github.com/plataformatec/devise/issues/913
https://github.com/ryanb/cancan/issues/280
I'm trying out some of the suggestions on those threads and will post if I find a solution.
I had a similar problem. Solution was as simple as adding
<%= csrf_meta_tag %>
to the layout.
It turns out this had to do with changes to the Rails jQuery UJS driver and Devise. I had updated Devise without updating jQuery UJS -- and Devise was expecting the CSRF token to be handled differently, so it was processing the ajax request as unauthorized which meant destroying the current user's session. Upgrading to the latest jQuery Rails driver fixed the problem.
Are you sure this controller and action are the ones that are triggered by the request? It sounds like the path you are DELETEing isnt right and you are hitting your sessions path instead.
Is it possible that the destroy notification path is redirecting to the session destroy path through JS?
Do you have destroy.js template in your notifications views? try adding one that is empty see if you get a different result.

Resources