Skip to content

Instantly share code, notes, and snippets.

View MiguelSavignano's full-sized avatar

Miguel Savignano MiguelSavignano

View GitHub Profile
#/routes.rb
get "/productos/:name" => 'products#show', as: :products
#/controller.rb
def show
#buscar producto
end
<ul class=” <%= get_price_css(@product) %>”>
<li> Nombre: <%=@product.name %></li>
<li> Precio: <%=@product.get_price %></li>
<li> Fabricante: <%=@product.maker_name || “No disponible” %></li>
</ul>
module ProductHelper
def get_price_css(product)
product.is_in_promotion ? "product-promotion" : "product"
end
end
@MiguelSavignano
MiguelSavignano / date_format.rb
Created September 27, 2016 15:42
Set default date format in the rails view
# Date
# ----------------------------
Date::DATE_FORMATS[:default] = "%d/%m/%Y" # 03-01-2016
#Date::DATE_FORMATS[:default] = "&proc" # November 3rd, 2013
#Date::DATE_FORMATS[:default] = "%B %e, %Y" # November 3, 2013
#Date::DATE_FORMATS[:default] = "%e %b %Y" # 3 Nov 2013
#Date::DATE_FORMATS[:default] = "%Y%m%d" # 20131103
#Date::DATE_FORMATS[:default] = "%e %b" # 3 Nov
#Date::DATE_FORMATS[:default] = "" # custom
@MiguelSavignano
MiguelSavignano / Setting.rb
Created November 8, 2016 00:39
rails setting mongoid
class Setting
include Mongoid::Document
field :support_email, type: String, default: ""
def self.method_missing(method, *agrs, &block)
_initialize unless first
first.send(method, *agrs, &block)
end
@MiguelSavignano
MiguelSavignano / tab_helper.rb
Last active November 17, 2016 23:45
Tabs rails
def link_tab(content, tab_name, options={})
prefix_active = "active"
tab_name = tab_name.to_s
css_class =
if params[:tab].blank?
options[:default] ? prefix_active : nil
elsif params[:tab] == tab_name
prefix_active
end
link_to content, current_path({tab: tab_name}), class: css_class
import React, { PropTypes } from 'react'
import ReactOnRails from 'react-on-rails'
import {Api} from '../../app'
export class PaginateMore extends React.Component {
constructor(props) {
super(props)
const current_page = this.props.current_page || 1
this.offset = this.props.offset || 0.8
this.state ={
@MiguelSavignano
MiguelSavignano / delete-on-click-in-dom.js
Last active March 1, 2017 17:44
This delete the onclick string in the html dombut it's works same, auto create event listener with the code Example
window.ClearDOM = {
clearOnClick: function(element){
var code_block = $(element).attr('onclick')
$(element).on('click', function(event){
eval( code_block )
})
$(element).attr('onclick', '')
},
run: function(selector){
$('*[onclick]').toArray().forEach( (element) => ClearDOM.clearOnClick(element) )
@MiguelSavignano
MiguelSavignano / es_next.js
Created March 19, 2017 00:20
Test new features in javascript
function printArguments(target, name, descriptor) {
let oldFunction = descriptor.value
descriptor.value = function () {
console.log(`start ${name} with arguments`, arguments)
oldFunction.apply(target, arguments)
console.log(`end function ${name}`)
}
return descriptor
//if else in jsx
//we need to render the tab view if the tab it's active, and loop the users if not users show empty message
//option 1
render(){
const {users, tab_active} = this.state
return (
<div>
{ tab_active == "users" && (