Ruby on Rails - How to set up Ahoy Gem - ruby-on-rails

Im setting up Ahoy gem into my application, but there are some options that I don't understand where to add.
This is what I have done currently:
1) Added gem "ahoy_matey" to my Gem File and ran Bundle install & restarted my server
2) Added //= require jquery & //= require ahoy to my application.js
3) Ran rails generate ahoy:stores:active_record and added new tables to my database by running rake db:migrate
I also have ahoy.rb in my initializers folder.
At this point I can see that ahoy is added in my application, but not sure how to do some stuff.
I want to add Ahoy.cookie_domain = :all & Ahoy.visit_duration = 1.minute, But I don't know where to add them
AND one other issue I have is that whatever page I go to is added to my Visits table (PS: I haven't added any JS or Ruby code for tracking in any pages or controller) and as I see it ,ahoy gem tracks all events/visits in my application. I only want to track events/visits on one particular action in my whole application, posts#show action and rest don't need to be added at all.
How can I achieve this?

I want to add Ahoy.cookie_domain = :all & Ahoy.visit_duration = 1.minute, But I don't know where to add them
You add them in the initializer that you created (./config/initializers/ahoy.rb). This is precisely the purpose of files in that folder: Setting configuration values for the application to use.
whatever page I go to is added to my Visits table [...] I only want to track events/visits on one particular action in my whole application
The Gem's README says:
There are three ways to track events. [...] See Ahoy.js for a complete list of features.
So start there, and take a look at ahoy.js if you need some more advanced configuration. The gem is very flexible - you just need to read the documentation and configure it as needed.

Related

How to implement the social sharing in rails app?

I want to implement the social sharing feature of the articles which have been posted in my rails app. I tried following the documentation of gem 'social-share-button' where the following steps were followed :
step 1: Add //= require rails-social-share-button in app/assets/javascripts/application.js
step 2: Add *= require rails-social-share-button in app/assets/stylesheets/application.css
step 3: use the social_share_button_tag helper method in views to display the social share buttons. for e.g = rails_social_share_button_tag('Share to Facebook', url: article_path(#article), desc: #article.content)
Error:
undefined method `rails_social_share_button_tag' for #<#:0x00005574ff28ec30>
You're missing a step or two from the gem's readme. The order of the instructions in the readme is a little misleading. Did you run rails generate rails_social_share_button:install? You may also want to check the contents of the "config/initializers/rails_social_share_button.rb" file after you've run that generator.
Alternatively, you may want to use the "social-share-button" gem. It looks like the one you're using, with its longer name, is a copy of everything in shorter-named "social-share-button" gem. Also it looks like the "social-share-button" gem has been around longer and is better maintained, as it already includes one bugfix that the gem you're using does not. I'd recommend first switching gems and then running bundle install. After switching gems, you should run the generator command listed in the readme for social-share-button, check the config file as the readme recommends, and then update your views accordingly.

Creating a gem for cells components

I want to create UI components to enable users to edit data present in a specified structure. I decided to give Cells a try, but I need to encapsulate the whole code in a gem, since I want to provide this components as an extension to an existing gem (criteria_operator), which is the source of the classes used for the data.
Is this possible? And if yes, how do I start? Normally, cells expects you to create views and models in specific folders of the default rails folder structure. When creating a gem, I only have the lib folder...
If you need any additional information, please just point it out in the comments. I wasn't sure if there is anything useful I could provide.
Disclaimer: The gem mentioned was created by me, and this question isn't intended to promote it.
To use another gem- criteria_operator, just add it to your gemspec:
s.add_runtime_dependency('gem_name', '~> <version>')
or add it to your gems's Gemfile.
To have models and views in your gem, you can use rails engine.
Rails engine allow you to wrap a specific Rails application or subset of it inside a gem.

Can't find spree folder in views in rails 4 app. How do i customize it?

I just integrated spree and zurb foundation on a rails 4 app and spree did not add any .html.erb files in views so I am not able to figure out how to customize the default layout of spree.
harriss-air:montrealfixed harrisrobin$ spree install --auto-accept
gemfile spree
gemfile spree_gateway
gemfile spree_auth_devise
run bundle install from "."
identical config/initializers/spree.rb
identical config/spree.yml
remove public/index.html
append public/robots.txt
exist app/assets/javascripts/store
exist app/assets/javascripts/admin
exist app/assets/stylesheets/store
exist app/assets/stylesheets/admin
exist app/assets/images/store
exist app/assets/images/admin
identical app/assets/javascripts/store/all.js
identical app/assets/stylesheets/store/all.css
identical app/assets/javascripts/admin/all.js
identical app/assets/stylesheets/admin/all.css
exist app/overrides
append db/seeds.rb
copying migrations
creating database
running migrations
loading seed data
loading sample data
insert config/routes.rb
**************************************************
We added the following line to your application's config/routes.rb file:
mount Spree::Core::Engine, :at => '/'
**************************************************
Spree has been installed successfully. You're all ready to go!
Everything goes smoothly when i install it.. but my app > views file is still the same, no spree folder. I can only see application.html.erb in layouts. So the question is.. how do i customize spree on rails 4 ? more specifically, how do i do the latter using zurb-foundation.
Spree provides a helpful customization guide located here:
http://guides.spreecommerce.com/developer/view.html
The views are being loaded from the Spree gem. You can type bundle show spree_frontend in order to see where the files are located on your filesystem. It should give you the list of files shown here (depending on your version):
https://github.com/spree/spree/tree/v2.1.2/frontend
Adding zurb-foundation in to Spree is going to be an invasive change. You may want to start with some smaller changes first to get the hang of customizing Spree.
Ok so to find the loaded views you have to use "bundle show spree" as gmacdougall suggested.
Can anyone please point me towards the right direction for integrating the foundation framework on a rails spree project ?
Thank you !
EDIT : while i did not find anything for foundation, i figured out that overriding the views so that it works with the foundation framework can be a lot of work and might not be a good idea for a noob like myself, so i found this
https://github.com/jdutil/spree_bootstrap
This replaces the spree front end with twitter bootstrap. Would have preferred Zurb Foundation but this is good!

How to add wrapbootstrap (made with twitter bootstrap) themes to rails application

The website https://wrapbootstrap.com/ has themes which were made using Twitter Bootstrap. Each of these themes include different versions of Twitter Bootstrap along with other various libraries and versions (jquery, fontawesome, etc...)
How do I add these themes to my existing Rails app? What are the steps?
I'm especially curious about the conflicts that may arrise if I'm already using a different version of jquery, twitter bootstrap, fontawesome, and others (as declared in the Gemfile).
Thank you
You can add the css from the theme you purchased from wrapbootstrap to your assets > application.css.scss file. And use the html tags that came with the theme in your rails app views so that the css styling is applied.
Also, I would recommend using gem 'sass-rails' to import the standard bootstrap styling.
Here's a tutorial to get you started with adding bootstrap to a rails app. Adding the theme css and html tags is up to you.
http://railscasts.com/episodes/328-twitter-bootstrap-basics?view=asciicast
I did this for few of the projects, I agree with majorly what Mike has answered above. Here are some of the gotchas I saw.
We started as a standard project on Rails all our views dynamic(Ember)/static were based on Bootstrap CSS. When major internal pages were up and functionality demonstrated we focused on landing pages. By this time we had the gems for bootstrap, fontawesome added to our Gemfile.
So one of the thing is to remove these gems "bootstrap", "fontawesome" from Gemfile. Include these as part of your wrapbootstrap dump.
Also as you progress with integration you may realize that a lot of common code is being repeated, its in your best interest to split the page components: headers, footers other things as partial Rails views. It severely saves the editing effort.
Another thing I found extremely useful to keep every thing up while you are still in integration stage, is to split your CSS/JS includes for pages imported from wrap bootstrap and pages you already have. So if you intend to migrate all existing pages into new theme scraping your CSS, then it can be merged in stages, otherwise you can let them co-exist.
You have to add new entries in routes.rb, controller calls to support the pages if you don't have them already. Likes of about, contactus, team etc. etc.
And if you use something like Ember/Backbone then you have to manage the co-existence of single pager app in some pages which may or may not be linked to the Wrapbootstrap pages.
This was all the things I had to take care off when I integrated the wrapbootstrap theme on top of Rails-EmberJS app.
Interesting timing as I just had to do this myself. I'm still fairly new to Rails so this might not be the best solution, but here's how I got it working ...
Note: every theme is different so this may not be a one size fits all approach.
1) My theme was built with Middleman and it was expecting to run stand alone or on a Sinatra instance.
2) In order to get the theme up on Rails, I had to add the compass gem, the sass gem, the sass-rails gem, and the compass-rails gem to work properly. I'm assuming you can install these (if required for your theme).
3) Assuming you have a Rails app ready to roll, go into your assets directory and backup your .js, .css, and all fonts and images. Place your theme asset files in the appropriate place.
4) Now do the same with your view layer. You may have a partials and/or pages folder which you can place in the views directory. You'll want to put application.erb.html and any navigation files in the layouts folder under the views directory. Again, make sure you back up your original files first.
5) If your theme was designed for Sinatra, you may have a Config.rb file. I moved the logic from this file into my config/environment.rb file. I was the least confident with this step. Other Rails devs can chime in if there is a better location.
6) Start your server up. You may encounter some exceptions but this is to be expected.
7) Take a look at your old app/assets/javascripts/application.js file and compare it to the new file. Ensure that the new file has the jquery ujs library included //= require jquery_ujs . Without this bit of magic your PUT and DELETE HTTP verbs won't work properly.
8) Path adjustments. My theme had the Font Awesome library included. In order to get it to work, I had to adjust the reference paths at the top of the font-awesome.scss file.
9) Finally, you'll need to debug the newly added code in the environment.rb file. The Sinatra developer was doing a lot of Route magic to adjust the navigation display. This wasn't porting over well to my environment. I removed many of these calls from my navigation template files. Once complete, my newly skinned app was up and running! Good luck.
make sure that while installing twitter bootstrap you should add following gem into your Gemfile under "group :assets"
gem 'therubyracer'
gem 'less-rails'
gem 'twitter-bootstrap-rails'
then run bundle command.
Now, the theme "file_name.css" (file_name could be any) that u have downloaded just add it into "stylesheets" folder under app->assests->stylesheets
then open your application.css file in same folder there you will see
*= require_tree.
replace this line with
*= require "file_name.css"
NOTE: Don't forget to re-compile your assets or simply delete the content of your tmp/cache folder.
save it and reboot your server. it will apply youe new theme.
Watch this training course which guide you to do so in detail and from scratch.
http://pluralsight.com/training/courses/TableOfContents?courseName=getting-started-aspdotnet-mvcservice-stack-bootstrap

How to configure Rails 3.1 app from a gem?

For example, I want to change rails settings when I require my gem to application.
If I simply put this line
Rails.application.config.assets.prefix = '/app/themes/default/assets'
into my gem, this does not change the settings. I think I need to use some rails hooks there.
Please help me guys
You shouldn't need to configure the path of the assets. When put in the proper place, they should load automatically. You need to define an "Engine". Have a look at a gem I made: https://github.com/iain/formalize-rails

Resources