Skip to content

Instantly share code, notes, and snippets.

View ysinc88's full-sized avatar

yair segal ysinc88

  • LED Yair
  • Israel
View GitHub Profile
@ysinc88
ysinc88 / error.txt
Last active August 29, 2015 14:24
Trying to understand join tables in Rails
NameError in LampsController#index
uninitialized constant Lamp::Constituents
Extracted source (around line #158):
156
157
158
159
160
161
@ysinc88
ysinc88 / controllers.rb
Last active August 29, 2015 14:25
Rails nested simple_form.
class LampsController < ApplicationController
before_action :set_lamp, only: [:show, :edit, :update, :destroy]
def edit
@lamps = Lamp.all
end
private
def set_lamp
@lamp = Lamp.friendly.find(params[:id])
@ysinc88
ysinc88 / Models.rb
Created July 26, 2015 15:00
Rails collection selected preselected according to param
class Question < ActiveRecord::Base
has_many :answers
end
class Answer < ActiveRecord::Base
belongs_to :user
belongs_to :question
end
class User < ActiveRecord::Base
<header>
<div class="logo" >
<a itemprop="url" href="http://ledyair.com" href="/"><img itemprop="logo" src="<%= asset_path("vineLogo.png") %>" alt="LEDYair logo" /></a>
</div>
<nav>
<div id="nav-xs">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#nav-lg" aria-expanded="false" aria-controls="navbar">
@ysinc88
ysinc88 / index.html
Last active August 29, 2015 14:27
Chat tutorial from socket.io
<!doctype html>
<html>
<head>
<title>Socket.IO chat</title>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font: 13px Helvetica, Arial; }
form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
@ysinc88
ysinc88 / phone.rb
Created August 16, 2015 17:04
Multiple slugs FriendlyId
class Phone < ActiveRecord::Base
belongs_to :user
end
@ysinc88
ysinc88 / controllers.rb
Last active August 29, 2015 14:27
Create json nested attributes
class UsersController < ApplicationController
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
@ysinc88
ysinc88 / seeds.rb
Created September 16, 2015 10:21
seeding from excel
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
require 'roo'
def fetch_excel_data
@ysinc88
ysinc88 / index.html
Last active September 19, 2015 19:46
Form log not working
<!DOCTYPE html >
<html lang="en"
ng-app="minmax" >
<head >
<title >Controllers</title >
<link href="../libs/bootstrap/bootstrap.min.css"
rel="stylesheet" >
<link href="main.css"
rel="stylesheet" >
</head >
@ysinc88
ysinc88 / readme.txt
Last active November 11, 2015 18:13
Creating new lines from the commas inside quotes
So I have no code, because i have no idea how to do this...
I am looking for a link to start reading...
Taking this sample row:
original:
--bRP68Ey4M,Natalie Imbruglia Torn,16,0,USD,"Torn,,Torn,","GB1109700440,,GBARL0400487,",,",emipub|UMPG,,emipub|UMPG","Natalie Imbruglia,,Various,"
desired output:
=--bRP68Ey4M,Natalie Imbruglia Torn,16,0,USD,Torn,GB1109700440,,,Natalie Imbruglia
=--bRP68Ey4M,Natalie Imbruglia Torn,16,0,USD,,,,emipub|UMPG,
=--bRP68Ey4M,Natalie Imbruglia Torn,16,0,USD,Torn,GBARL0400487,,,Various