unable to use ahoy gem for usage tracking - ruby-on-rails

I'm trying to use ahoy_matey gem in development env. i.e. Windows7 64 bit and rails 4.0.9 by following the doc at https://github.com/ankane/ahoy.
I would like to use this gem to track user visits and ip addresses in particular and then restrict the number of sign-in's per IP address. I've followed the readme file but unable to see records in visits table in my pg db.
Below are the steps I've followed so far -
gem 'ahoy_matey' #included in gem file and ran bundle install
//= require ahoy # included this line in application.js file
rails generate ahoy:stores:active_record -d postgresql
rake db:migrate
gem 'fluent-logger' #ran bundle install after including this line in gem file
The below command generated an error- Could not find generator ahoy:stores:fluentd.
rails generate ahoy:stores:fluentd
I've tried including below script in /layout/application.html.erb and other pages as well inside script tags without success.
ahoy.trackAll();
included the below in my sign in method in session controller
ahoy.authenticate(user)
Included the below in my index method of landing page without success.
ahoy.track "Viewed Landing", title: "Landing page viewed"
The only thing that has worked so far is below code which I've added in my application controller and it is populating my ahoy_events table.
class ApplicationController < ActionController::Base
after_filter :track_action
def track_action
ahoy.track "Processed #{controller_name}##{action_name}", request.filtered_parameters
end
I've also restarted my rails webserver (I'm using thin in dev and puma in prod).
Could you please let me know what I'm missing here. What do I need to do differently with my ahoy setup to enable it to start writing records to the "visits table" in my pg database.
Any pointers will be appreciated.
TIA

have you try to find some js code that may not be compliant with browsers that doesn't appear in visits table ?
edit :
I detail my idea : if you have any js code not compliant that make browser didn't get 200 http success and then the page loading fail, if your ahoy call is after that, browser didn't execute it

Related

Ruby on Rails Vacuum Gem

I am new to Ruby on Rails and I am trying to access the Amazon Product API using the Vacuum Gem. Based off this code https://gist.github.com/frankie-loves-jesus/89d24dd88579c7f912f3 I am getting an error at the first line
request = Vacuum.new('GB')
telling me that I have an "Uninitialized constant AmazonAPIController::Vacuum" every example on this gem tells me to use this line of code but I can't understand how to fix the error. It seems to be as simple as putting the code into my controller and showing it.
You didn't add the gem to your Gemfile I guess and didn't run bundle install afterwards. Also you should make sure to restart your Rails server after every change in your Gemfile.
If all that doesn't help, you also could try to just gem install vacuum and then require 'vacuum' in the file you are using (but I would recommend getting it to work on another way).

Ahoy is not recording events or visits

I have installed Ahoy to give some user analytics on my rails application. I am running rails 4.1.10 and using Postgres 9.3.10
I have added the gem to my gemfile:
gem 'ahoy_matey'
And I have run :
rails generate ahoy:stores:active_record -d postgresql
rake db:migrate
As per the docs.
I also added //=require ahoy after jquery in the application.js assets file.
I was not sure if visits and events would be tracked automatically - so I went to a couple of pages and checked manually in the DB and I see no entries in the visits or ahoy_events tables. So I manually coded this into my landing page index controller action:
ahoy.track "Viewed Landing", title: "Landing page viewed"
And this line causes the following error:
NameError in LandingPageController#index
undefined local variable or method `ahoy' for #<LandingPageController:0x007fa634fee7f0>
(Listed in full here : https://gist.github.com/renegadeandy/835a7fb0db2bb9d8ea95)
Can anybody help me get ahoy logging visits and events please! Ideally I want it to track everything, automatically if there is some golden switch I need to press :)
The problem was that the server had not been restarted :'(
Closing the server and reopening it - solved the problem!

Heroku and HighCharts Rails Gem -

I created a rails app using the HighCharts gem and an external API to seed the db. Everything works perfectly on my local server but when I deployed to Heroku (using postgreSQL) and running all the heroku run rake db:migrate, db:seed commands, my chart does not load.
I get the following error in my console:
Mixed Content: The page at 'https://myappname.herokuapp.com/' was loaded over HTTPS, but requested an insecure stylesheet 'http://fonts.googleapis.com/css?family=Signika:400,700'. This request has been blocked; the content must be served over HTTPS.
I am using a theme which I require in my application.js file that uses googlefonts via HTTP (NOT HTTPS) and I think I need to change this to //fonts.google... but I don't know how since I'm using the gem.
When I tell my browser (Chrome) to display the insecure scripts, the chart still does not appear and the console spits out an empty array which tells me my data is not in Heroku.
Please let me know what other info I can provide. As you can see I think I have 2 issues.
Thank you!
With the help of the HighCharts Rails gem folks, I was able to manually download the source code and change the pertinent parts to be protocol independent. All it required was copying the theme.js code into app/assets/javascripts, make the changes, and load that file instead of //= require highcharts/themes/sand-signika in my application.js.
Am still having an issue with data not migrating from my local db to Heroku...

Creating rails 3 gems: Gems installing successfully, but no functionality

I'm trying to create my first rails gem with jeweller - it's a very simple demo gem with just a "Tester" model and a "Frog" scaffold.
The gem packages up just fine, gem contents "testgem" confirms the desired files are packaged into the gem, and when I "bundle install" it, everything seems to go OK & the gem is in the list of installed gems.
...BUT - I'm not getting any functionality. The activerecord model isn't recognised from the command line (Command "Tester" returns "uninitialized constant Tester"), and the controllers aren't being found either, even when I manually add the resources to config/routes.
This is my first self-built gem, so I could be missing something simple. I've tried placing the necessary files in both [GEM_ROOT]/lib/app/ and [GEM_ROOT]/app/, with gem.path set to [{lib}//, {app}//*].
Any suggestions most appreciated. ;-)
Ach - terribly embarrassing - 30 mins after posting I figured it out.
In case anyone else is wondering: In the gem, I wasn't directing the mygemname.rb file to the engine.rb file. In short, I needed
require 'mygemname/engine' if defined?(Rails)

What's your solution for 'contact forms' in Ruby on Rails applications?

With a quick Google search, one can find literally hundreds of examples for contact forms using PHP and/or JavaScript, but there don't seem to be any "ready-made" contact forms for Ruby on Rails. Do they exist? What do you use for contact forms in your Ruby on Rails apps?
Personally, I use an ActiveRecord model for mine as I like to keep a store of messages being sent, and then use an ActionMailer after saving a record to send an email.
Alternatively there is a gem called MailForm which allows you to build a form model without a database table, which will work with other gems such as Formtastic.
As for ready-made contact forms, I don't know of any (though they may well exist) as it's not particularly time-consuming to build one from scratch.
I was running into the same issue with wanting an easy to use out of the box Contact Form, but wasn't able to find one. So I've written ContactUs a Rails Engine that you can easily drop into any Rails 3+ application. I tried to keep it dead simple and as easily configurable as possible. It does require the Formtastic gem since I wanted an easy way to hook into peoples existing form styles though.
To install the Engine add the contact_us gem to your Gemfile:
gem 'contact_us', '~> 0.1.3'
Run bundle and the install rake task:
$ bundle
$ bundle exec rake contact_us:install
Then just modify the generated initializer in /config/initializers/contact_us.rb to have the email you want the form submissions sent to.

Resources