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 / 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 / phone.rb
Created August 16, 2015 17:04
Multiple slugs FriendlyId
class Phone < ActiveRecord::Base
belongs_to :user
end
@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%; }
<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 / 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
@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 / 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 / welcome.html.erb
Created May 24, 2015 14:32
Execute bash script
<h1><%= @download %></h1>
<%= link_to "download", download_path(:ydit => "SB8-YY2DyHI") %>
<ul>
<% @mp3s.each do |m| %>
<li><%= m %></li>
<% end %>
</ul>
<% @sections.each do |s| %>
<tr>
<td><%= s.header %></td>
<td><%= truncate(sanitize(s.content), length: 80) %>
</td>
<td><%= link_to "edit", edit_admin_section_path(s) %></td>
</tr>
<% end %>
@ysinc88
ysinc88 / controller.rb
Created April 4, 2015 11:59
each loop from 2 models
class PagesController < ApplicationController
def store
@products = Product.all
end
end