Skip to content

Instantly share code, notes, and snippets.

View RicharCor's full-sized avatar

Ricardo Cor RicharCor

View GitHub Profile
@RicharCor
RicharCor / respondents_controller.rb
Created January 25, 2019 06:25
Controlador respondents
#No olvides las asociaciones en los modelos
class RespondentsController < ApplicationController
#info del controlador
before_action :find_survey, only: [:create]
#info del controller
def create
@respondent = @survey.respondents.new(respondent_params)
@RicharCor
RicharCor / application_helper.rb
Last active January 12, 2019 23:03
Time ago in words a español
module ApplicationHelper
def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false)
from_time = from_time.to_time if from_time.respond_to?(:to_time)
to_time = to_time.to_time if to_time.respond_to?(:to_time)
distance_in_minutes = (((to_time - from_time).abs)/60).round
distance_in_seconds = ((to_time - from_time).abs).round
case distance_in_minutes
when 0..1
return (distance_in_minutes == 0) ? 'menos de un minuto' : '1 minuto' unless include_seconds