Skip to content

Instantly share code, notes, and snippets.

View salami-art's full-sized avatar

salami-art

View GitHub Profile
@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 / _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>
class Author < ActiveRecord::Base
validates :name, :presence => true
has_many :books
end
[............]
# 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>
@import 'books.css.scss'
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)
#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