Skip to content

Instantly share code, notes, and snippets.

View salami-art's full-sized avatar

salami-art

View GitHub Profile
#class Class
def remove
puts "find hash to remove"
search = $stdin.gets.chomp.each_line(separator=" ").to_a
result = address_book.query search
#puts result => returns expected hash
address_book.remove result
end
require File.expand_path('../boot', __FILE__)
require 'rails/all'
config.autoload_paths += %W(#{config.root}/lib)
require 'ext/string'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
@import 'books.css.scss'
[............]
# code wich is inside the loop and has the odd, even cycle css pattern
<% @books.each do |book| %>
<tr class=<%= cycle("odd", "even") %>>
<td><%= book.id %></td>
<td><%= book.author.name %></td>
class Author < ActiveRecord::Base
validates :name, :presence => true
has_many :books
end
@salami-art
salami-art / _form.rb
Created November 20, 2013 13:53
Want to create a new author using "Author" field in the form in books/new, if it doesn't exist yet. The code provided in _form is not working. Routes autor/new, author/create are available.
<%= form_for([@author, @book]) do |f| %>
<% if @book.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@book.errors.count, "error") %> prohibited this book from being saved:</h2>
<ul>
<% @book.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
@salami-art
salami-art / author.rb
Created November 20, 2013 20:09
I can create a new book, as desired, in pair with its author by running: > book = Book.create(:title => "title", :author_attributes => {:name => "name"}, :text => "text") However, every attempt to post via http results in error: "Author can't be blank" I've already tried with: [...] <%= fields_for :author , @book.author do |ff| %> <li>Author<br>…
class Author < ActiveRecord::Base
validates :name, :presence => true
has_many :books, :inverse_of => :authors
end
@salami-art
salami-art / controller
Created November 20, 2013 23:45
'books' route called with redirect_to assigns variable as expected, Action :index (same page) called with render doesn't.
class BooksController < ApplicationController
def index
@books = Book.all # # this variable doesn't get loaded with " render "
respond_to do |format|
format.html
format.yaml { render text:@books.to_yaml }
format.json { render text:@books.to_json }
var sizes = {
'-small' : 200,
'-medium': 600,
'-large' : 1040,
}
for (var suffix in sizes){
if (sizes.hasOwnProperty(suffix)) {
var finalName = uploadUrl+fileName+suffix+fileExtension;
var stream = fs.createWriteStream(finalName);
var images = gallery.images;
for (var i = 0; i < images.length; i++ )
{
console.log(JSON.stringify(images[i]));
for (var key in images[i])
{
(function (key) {
if (images[i].hasOwnProperty(key))
{