Skip to content

Instantly share code, notes, and snippets.

in _form.html.erb
<%= error_messages_for @books %>
<p>Name of book: <%= text_field :name, :size =>"40" %></p>
<p><%= "&nbsp;" * 13 %>Author: <%= select :author_id, :collection => Author.all.map {|u| [u.id, full_name(u.first_name, u.last_name)]} %>
<p><%= "&nbsp;" * 5 %>Description: <%= text_area :description, :cols => "40", :rows => "2", :wrap => "SOFT" %></p>
<p><%= "&nbsp;" * 17 %>Price: <%= text_field :price, :size => "7" %></p>
[518] Mercredi 17/12/2008 08:07:04 CET +0100
[RubyLearning/Merb/ruby_bookshop
$ merb
Loading init file from /PortefeuillePartage/Ruby/RubyLearning/Merb/ruby_bookshop/config/init.rb
Loading /PortefeuillePartage/Ruby/RubyLearning/Merb/ruby_bookshop/config/environments/development.rb
~ Connecting to database...
~ Loaded slice 'MerbAuthSlicePassword' ...
~ Parent pid: 4178
~ Compiling routes...
~ Activating slice 'MerbAuthSlicePassword' ...
rake db:automigrate
(in /PortefeuillePartage/Ruby/RubyLearning/Merb/ruby_bookshop)
Loading init file from /PortefeuillePartage/Ruby/RubyLearning/Merb/ruby_bookshop/config/init.rb
Loading /PortefeuillePartage/Ruby/RubyLearning/Merb/ruby_bookshop/config/environments/development.rb
Loading init file from /PortefeuillePartage/Ruby/RubyLearning/Merb/ruby_bookshop/config/init.rb
Loading /PortefeuillePartage/Ruby/RubyLearning/Merb/ruby_bookshop/config/environments/rake.rb
rake aborted!
default store already setup
/PortefeuillePartage/Ruby/RubyLearning/Merb/ruby_bookshop/rakefile:24
(See full trace by running task with --trace)
@migane
migane / gist:3425206
Created August 22, 2012 12:42
Text reverse, palindrome, concatenation in sinatra
# Main file string_reverse.rb
require 'sinatra'
helpers do
def concatenate_strings(string1, string2)
string1 + string2
end
@migane
migane / gist:3425304
Created August 22, 2012 12:49
Reverse text, palindrome and concatenation in ruby under sinatra
# Main file string_reverse.rb
require 'sinatra'
helpers do
def concatenate_strings(string1, string2)
string1 + string2
end
@migane
migane / gist:3611582
Created September 3, 2012 18:09
input number with rack
# input_number.rb
def input_response(n)
answer = ""
if n > 0
answer = "positive"
elsif n < 0
answer = "negative"
else n == 0
answer = "zero"
end
@migane
migane / gist:3619842
Created September 4, 2012 10:31
Reverse world in sentence with rack
#my_rack_mtd.rb
require 'rack'
error = false
def check_argument
if (ARGV.length < 1 || ARGV.length > 1 || ARGV[0].split(" ").size < 2)
error = true
end
return error
@migane
migane / gist:3625040
Created September 4, 2012 18:59
Reverse world in sentence with rack revisited
#my_rack_mtd1.rb
# Revisited version
require 'rack'
def reverse_word_order(env)
if (ARGV.length < 1 || ARGV.length > 1 || ARGV[0].split(" ").size < 2)
[400, {}, ["Enter one sentence with at least two words to reverse the sentence"]]
else
[200, {}, [ARGV[0].split(" ").reverse.join(" ")]]
@migane
migane / gist:3654789
Created September 6, 2012 10:56
Reverse world in sentence with rackup
# config.ru
require './my_app_bis.rb'
run MyAppBis.new
# my_app_bis.rb
class MyAppBis
def initialize()
@str = "Is not rackup fun, is it?"
end
@migane
migane / gist:3654907
Created September 6, 2012 11:10
Reverse world in sentence with rack and form
# my_app_ter.ru
use Rack::MethodOverride
map '/' do
form = <<-HERE
<form action="/reverse_word" method="post">
<input name="_method" type="hidden" value="put" />
<input name="sentence" type="text" value="" />
<input type="submit" value="Reverse the words order">