Skip to content

Instantly share code, notes, and snippets.

View achmiral's full-sized avatar
🏠
WFH

Miral Achmed achmiral

🏠
WFH
View GitHub Profile
@SunDi3yansyah
SunDi3yansyah / README.md
Created July 19, 2018 09:24 — forked from timcheadle/README.md
Make /robots.txt aware of the Rails environment

Make /robots.txt aware of the Rails environment

You probably don't want Google crawling your development staging app. Here's how to fix that.

$ mv public/robots.txt config/robots.production.txt
$ cp config/robots.production.txt config/robots.development.txt

Now edit config/routes.rb to add a route for /robots.txt, and add the controller code.

Realtime Notifications with ActionCable

In this episode we're going to be adding realtime notifications into your app using ActionCable. We've talked about notifications a few times in the past and we used AJAX polling for that. 95% of the time, polling is the solution that would be recommended for it.

But if you're looking for a good introduction into ActionCable then this is a decent one because we're only really using it for one way from the server side to the client side.

Getting started

So to get started we're starting with an app that has Bootstrap installed and then we created a Main controller with an index view which is where we will list our Notifications as for this example.

Before we generate our channels let's install a few things

Setup

Replace IRB with Pry (in your Gemfile) and Byebug with pry-byebug.

gem 'pry-rails', group: [:development, :test]
gem 'pry-byebug', group: [:development, :test]

Using PRY

@SunDi3yansyah
SunDi3yansyah / subdomain-localhost-rails-5.md
Created July 6, 2018 22:39 — forked from indiesquidge/subdomain-localhost-rails-5.md
how to access subdomains locally with Rails 5

Subdomaining Localhost with Rails 5

I've been following this blog post on how to set up an api-only Rails 5 application. One of the sections talks about creating a subdomain for your api

Rails.application.routes.draw do
  constraints subdomain: "api" do
    scope module: "api" do
@SunDi3yansyah
SunDi3yansyah / find_duplicate.rb
Last active October 1, 2021 14:06
Rails find duplicate records
columns_that_make_record_distinct = [:some_attribute]
distinct_ids = Model.select("MIN(id) as id").group(columns_that_make_record_distinct).map(&:id)
duplicate_records = Model.where.not(id: distinct_ids)
@SunDi3yansyah
SunDi3yansyah / manu-active-with.js
Last active November 10, 2018 06:02
Menu Active with JS
var url = window.location;
var element = $(".ui.vertical.menu a.item").filter(function() {
return this.href == url || url.href.indexOf(this.href) == 0;
}).addClass("active").parent().parent().parent();
if (element.is("li")) {
element.addClass("active");
}
@jenweber
jenweber / be-loud-be-ready.md
Last active November 29, 2018 17:00
Be loud and be ready - my hopes for Ember.js in 2018

Be loud and be ready - my hopes for Ember.js in 2018

In 2018, I want to see Ember grow. But how could that be done in a strategic way? In this article, I'll take stock of our current resources and suggest how we could focus our efforts.

Sometimes when I am not sure how to achieve a goal, I imagine my future, successful self. I imagine that the goal has been achieved, using the same resources I have today, and I work backwards. What would I guess that those successful people of Future-Ember did?

  1. The people of Future-Ember worked to increase public awareness so that more developers knew about it and considered it for their projects. The Core Team led by example, writing and speaking, and the rest of the community was empowered to do the same.
  2. Future-Ember provided approachable, current, convincing materials for new visitors.

They were LOUD, and they were ready for the moment that they were heard.

@mrmartineau
mrmartineau / stimulus.md
Last active October 5, 2025 14:09
Stimulus cheatsheet
@SunDi3yansyah
SunDi3yansyah / ActionController.rb
Last active November 13, 2021 17:13
Exception Handler, List Module/Class ActiveRecord & ActionController
irb(main):001:0> ActionController.constants.map { |ac| "ActionController::#{ac}" }.join(", ")
@SunDi3yansyah
SunDi3yansyah / rails-errors.md
Last active April 30, 2020 09:32
Rails Errors
@object.errors.full_messages.first
@object.errors
@object.errors.values.flatten.compact
@object.errors.messages.map {|e| { key: e.first, value: e.second } }