This repository has been archived by the owner. It is now read-only.
Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Datamapper fails to save to sqlite db #210
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
ciembor
Oct 31, 2012
Isn't it wrong because :url
? I have a property named :url
and I tray to use format => :url
, as you. In my case app hungs...
ciembor
commented
Oct 31, 2012
Isn't it wrong because |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
schilton commentedJun 22, 2012
Datamapper correctly creates the database in sqlite, but fails to persist an object to its table. The form returns the values and properly assigns them to the object, but the call to save the object fails. How do you determine why it failed so that I can correct the problem? I am a newbie to Ruby, Sinatra, Datamapper and Sqlite and any assistance would be greatly appreciated.
Here is the Ruby code savetest.rb :
require 'rubygems'
require 'i18n'
require 'sinatra'
require 'data_mapper'
require 'bcrypt'
enable :sessions
DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/savetest.db")
in config/initializer/locale.rb
tell the I18n library where to find your translations
I18n.load_path << Dir[File.join('config', 'locales','*.{rb,yml}') ]
class Entity
include DataMapper::Resource
property :entity_id, Serial
property :full_legal_name, String
property :tax_id, String
property :phone_number, String
property :fax_number, String
property :cell_number, String
property :email, String, :unique => true, :format => :email_address
property :alt_email, String
property :is_active, Boolean
property :created_at, DateTime
property :created_by, String
property :updated_at, DateTime
property :updated_by, String
property :auto_pay, Boolean
property :use_ach, Boolean
property :prefix, String
property :first_name, String
property :middle_name, String
property :last_name, String
property :suffix, String
property :referal_code, String
property :login_name, String, :unique => true
property :hashed_password, String
property :salt, String
property :permission_level, Integer
property :title, String
property :greeting, String
property :preferred_name, String
property :preferred_language, String
property :security_question, String
property :security_answer, String
property :signature_font, String
has n, :addresses, :through => Resource
has n, :aches
has n, :creditcards
end
class Person < Entity
property :birthdate, Date
property :drivers_license_number, String
property :state_issuing_drivers_license, String
end
class Company < Entity
property :dba_name, String
property :legal_structure, String
property :url, String, :format => :url
end
class Address
include DataMapper::Resource
property :address_id, Serial
property :esid, String
property :description, String
property :address_line1, String
property :address_line2, String
property :city, String
property :state, String
property :zipcode, String
property :country, String
property :meter_number, String
property :meter_type, String
property :meter_status, String
property :meter_status_date, DateTime
property :updated_by, String
property :switch_indicator, String
property :switch_type, String
property :selected_switch_date, Date
property :under_contract, Boolean
property :contract_end_date, Date
has n, :entities, :through => Resource
end
class Ach
include DataMapper::Resource
property :ach_id, Serial
property :bank_account_owner, String
property :bank_name, String
property :routing_number, String
property :bank_account_number, String
property :ach_authorization, Boolean
belongs_to :entity, :required => false
end
class Creditcard
include DataMapper::Resource
property :credit_card_id, Serial
property :type_of_card, String
property :card_number, String
property :expiration_date, Date
property :security_code, String
property :cardholder_name, String
property :credit_card_billing_address_line1, String
property :credit_card_billing_address_line2, String
property :credit_card_billing_city, String
property :credit_card_billing_state, String
property :credit_card_billing_zipcode, String
property :credit_card_authorization, Boolean
belongs_to :entity, :required => false
end
DataMapper.finalize
Create or upgrade all tables at once
DataMapper.auto_upgrade!
before do
#set utf-8 for outgoing
headers "Content-Type" => "text/html; charset=utf-8"
#set the locale manually - this will be replaced with code to extract it from the subdomain
I18n.locale = :en
end
get '/' do
redirect "/residential/signup"
end
get '/residential/signup' do
@title = I18n.t('residential_signup_title')
erb :residential_signup
end
post '/residential/signup' do
@title = "Residential Signup"
@home_menu = "home"
@ce_logo = "../assets/images/ceLogo.png"
@lgraphic = "../assets/images/TmpResidentialGraphic.png"
@international_gif = "../assets/images/international.gif"
@page_content = "The data collected is:
"
@person = Person.new()
params[:post].each { |key, value| @person[key] = value }
@test = params[:post][:prefix] + " " + params[:post][:first_name] + " " + params[:post][:middle_name] + " " + params[:post][:last_name] + " " + params[:post][:suffix]
@person.full_legal_name = @test
if @person.save == false
@sub = "The save failed!"
else
@sub = "The save succeeded!"
end
session[:foo] = @person
session[:base_route] = "residential"
if params[:post][:submit] == I18n.t('privacy_policy_label')
redirect "/privacy_policy"
elsif params[:post][:submit] == I18n.t('cancel_btn_label')
redirect "/residential"
else
@page_content = "The data collected is:
" + "
" + @sub
erb :index
end
end
Here is the view for the form residential_signup.erb :
<%= I18n.t('residential_signup_title') %>
<%= I18n.t('privacy_policy_review_caption') %>
English Español
|
Here is the view for the display index.erb :
Here is the layout view layout.erb :
<title><%= @title %></title> <script type="text/javascript" src="scripts/commonScripts.js"> </script><%= yield %>
Here is the CSS for main.css :
/*
Document : main
Created on : Sep 21, 2010, 11:36:02 AM
Author : cellp
Description:
Purpose of the stylesheet follows.
*/
/*
TODO customize this sample style
Syntax recommendation http://www.w3.org/TR/REC-CSS2/
*/
root {
display: block;
}
body {
font: 1em Verdana, Arial, Helvetica, sans-serif; /* 1em = 16pts /
background: #ABA99F;
margin: 0; / it's good practice to zero the margin and padding of the body element to account for differing browser defaults /
padding: 0;
text-align: center; / this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector /
color: #000000;
}
.float_left {float:left; margin: 0 .3em .3em 0;} / apply this class to any image or element with width - text will wrap it to the right /
.float_right {float:right; margin: 0 0 .3em .3em;} / apply this class to any image or element with width - text will wrap it to the left */
h1, h2, h3, h4, h5, h6, ul, ol, dl {
font-family: 'Trebuchet MS', Verdana, serif;
}
/* FONT SIZES FOR HEADINGS_/
h1 {font-size:2em; /_ 24pt /
}
h2 {font-size:1.5em; / 22pt /
line-height:1.25;
padding: 0 0 0 0;
}
h3 {
font-size:1.125em;
line-height: 1.5;
}
h4 {font-size:1em; / 18pt /
}
h5 {font-size:1em; / 16pt /
}
h6 {font-size:.875em; / 14pt */
}
/* my default styling of other XHTML elements */
p {font-size:1em;}
code {font-size:1.25em;}
cite {
font-size:.85em;
font-style:italic;
}
blockquote {
width:30%;
font-size:.7em;
margin:0 0 1em 1em;
padding:.3em .4em;
border-top:2px solid;
border-bottom:2px solid;
}
blockquote cite {
font-size:0.85em;
display: block;
}
abbr, acronym {
border-bottom:1px dashed #000;
cursor:default;
}
address {
margin:0 1em .75em 1em;
}
img {
border:0;
}
a:hover {
text-decoration:none;
}
a.active {
background: #F03;
}
.clear {
clear:both;
height: 0; /* only necessary for IE */
margin: 0;
padding: 0;
}
/* styles specific to LiveValidation */
fieldset {
display: inline-block;
padding: 30px 10px 0px 10px;
border:0;
position:relative;
padding:10px;
margin:10px;
}
/label {
display:block;
font:normal 12px/17px verdana;
}/
span.hint {
font:normal 11px/14px verdana;
background:#eee url("../_assets/_images/bg-span-hint-gray.gif") no-repeat top left;
border:1px solid #888;
padding:5px 5px 5px 40px;
width:250px;
z-index:100;
position:absolute;
margin: 1em 0px 0px 0px;
display:none;
}
.welldone span.hint {
font:normal 11px/14px verdana;
background:#9fd680 url("../_assets/_images/bg-span-hint-welldone.jpg") no-repeat top left;
border-color:#749e5c;
color:#000;
}
.kindagood span.hint {
background:#ffffcc url("../_assets/_images/bg-span-hint-kindagood.jpg") no-repeat top left;
border-color:#cc9933;
}
.welldone {
background:transparent url("../_assets/_images/bg-fieldset-welldone.gif") no-repeat 300px bottom ;
}
.kindagood {
background:transparent url("../_assets/_images/bg-fieldset-kindagood.gif") no-repeat right center ;
}
formRightColumn {
/* background: #ff6666; This is for development only */
}
input[name="emailAddress"] {
}
/* styles specific to this design */
container {
}
loginContainer {
}
.loginField {
padding: 15px 0px 0px 20px;
width: 200px;
color: #675845;
float: left;
}
loginButton input{
}
forgotPassword {
}
rememberMe {
}
.rememberMe {
color: #675845;
font-size: .8em;
display: inline;
padding-left: 5px;
}
errorContainer {
}
.errorCode {
margin: 0px;
text-align: center;
padding-bottom: 20px;
color: #993300;
}
errorContainer h3 {
}
errorContainer p {
}
errorContainer h5 {
}
globalHeader {
}
.signupFormHeader {
width: 950px;
position: absolute;
font-style: normal;
font-size: 3.5em;
color: #675845;
text-align: center;
z-index: 100;
margin: 15px auto 0px auto;
padding: 0px;
}
globalHeaderLogo {
}
globalHeader h3 {
}
.headerNav * {
margin: 0px;
padding: 0px;
}
.headerNav {
font-family: Arial, Helvetica, sans-serif;
font-size: 0.8em;
background: transparent;
margin: 14px 60px 0px 0px;
float: right;
padding: 0em;
position: relative;
}
.headerNav ul {
display: inline;
border-left: 0px solid #B9B8AF;
font-size: 1em;
margin: 0px;
}
.headerNav.transparent ul li a {
position: relative;
top: -2px;
}
.headerNav.transparent ul li a.home {
background: url(../assets/images/homeButton.png) no-repeat left top;
padding-top: 10px;
padding-right: 18px;
padding-bottom: 10px;
top: -4px;
}
.headerNav.transparent ul li a.home:hover {
background: url(../assets/images/homeButton.png) no-repeat 0px -20px;
padding-top: 10px;
padding-right: 18px;
padding-bottom: 10px;
}
.headerNav.transparent ul li.home {
visibility: visible;
cursor: default;
}
.headerNav.transparent ul li.none {
visibility: hidden;
cursor: default;
}
.headerNav li {
border-right: 0px solid #B9B8AF;
float: left;
list-style: none;
position: relative;
background: transparent;
display: inline;
}
.headerNav li p {
display: inline;
float: left;
position: relative;
}
.headerNav a {
background: #FFF;
text-decoration: none;
display: block;
padding: .2em 5px;
color: #E48254;
}
.headerNav a:hover {
color: #675845;
text-decoration: underline;
}
.headerNav ul li ul {
width: 5em;
margin: 0px;
border-width: 0px;
position: absolute;
display: none;
padding: 0px;
}
.headerNav ul li:hover ul {
display: block;
z-index: 1000;
}
.headerNav ul li ul li {
padding: 0px;
width: 100%;
border-right-width: 0px;
border-left-width: 0px;
margin-left: 15px;
}
.headerNav li li {
background: #E0E7C9;
border-bottom: 0px solid #B9B8AF;
}
.headerNav.transparent ul ul li { /* The lower the value, the greater the transparency /
opacity:0.9; / CSS3 - range 0 to 1 /
-moz-opacity:0.9; / Firefox - range 0 to 1 /
filter:alpha(opacity=90); / IE - range 0 to 100 */
}
.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
content {
}
primaryGraphic {
}
primaryText {
}
formLeftColumn {
/* background: #ffff99; This is for development only /
}
.fieldContainer {
display: block;
float: left;
padding: 10px 10px 0px 10px;
/ position:relative; This prevents tooltips from working. See if you really need it. */
}
privacyPolicyInstructions {
}
privacyPolicyInstructions p{
}
.commercialInstructions{
padding-top: 20px;
}
.residentialInstructions{
padding-top: 25%;
}
.saveButton {
display: block;
float: left;
margin-top: -.75em;
margin-left: 40%;
padding-top: 20px;
width: 100%;
}
.saveButton input {
color: #669966;
}
.saveButton input:hover {
color: #993300;
text-decoration: underline;
cursor: pointer;
}
globalFooter {
/* background: #66cccc; This is for testing purposes - teal */
}
globalFooter_Left {
}
globalFooter_Center {
}
globalFooter_Center a {
}
globalFooter_Center a:hover {
}
globalFooter_Center p {
}
globalFooter_Right {
}
.footerNav * {
margin: 0px;
padding: 0px;
}
.footerNav {
font-family: Arial, Helvetica, sans-serif;
font-size: 0.8em;
background: transparent;
margin: 0px;
float: left;
padding: 0em;
position: relative;
}
.footerNav ul {
display: inline;
border-left: 0px solid #B9B8AF;
font-size: 1em;
float: left;
margin: 0px;
}
.footerNav li {
border-right: 0px solid #B9B8AF;
float: left;
list-style: none;
position: relative;
background: transparent;
display: inline;
}
.footerNav a {
background: #FFF;
text-decoration: none;
display: block;
padding: .2em 5px;
color: #E48254;
}
.footerNav a:hover {
color: #675845;
text-decoration: underline;
}
.footerNav ul li ul {
width: 5em;
margin: 0px;
border-width: 0px;
position: absolute;
display: none;
padding: 0px;
}
.footerNav ul li:hover ul {
display: block;
z-index: 1000;
}
.footerNav.transparent ul ul li { /* The lower the value, the greater the transparency /
opacity:0.9; / CSS3 - range 0 to 1 /
-moz-opacity:0.9; / Firefox - range 0 to 1 /
filter:alpha(opacity=90); / IE - range 0 to 100 */
}
a.current , a.current:hover, a.current:active {
color: #478EB0;
background: #FFF;
cursor: default;
text-decoration: none;
}
globalFooter_Center a.current, #globalFooter_Center a.current:hover, #globalFooter_Center a.current:active {
}
signupFooter a.current, #signupFooter a.current:hover, #signupFooter a.current:active {
}
signupFooter {
}
signupFooter input {
}
signupFooter input:hover {
}
signupFooter p {
}
privacyPolicyButton {
}
privacyPolicyButton input {
}
goBackButton {
}
formColumnFour{
/* background: #ffff99;*/
padding-left: 10px;
overflow: auto;
border: medium ridge #B9B8AF;
font-size: .8em;
}
.esidOptions{
font-size: .75em;
}
searchEsidButton {
}
searchEsidButton:hover {
}
.selectedSwitchDateContainer {
display: block;
float: left;
padding: 15px 0px 0px 5px;
}
.contractDate{
margin-top: -10px;
}
[name="creditCardAuthorization"] {
display: block;
position: relative;
}
checkboxInstructions {
}
checkboxInstructions p{
}
checkboxInstructions p.achInstructions {
}
.sameBillingAddressInstructions{
padding-top: 0px;
}
.radioButtonInstructions{
font-size: .8em;
}
.radioButton {
margin-top: 10px;
}
.radioButtonLabel {
margin: 10px 20px 0px 5px;
}
.infoContainer {
display: block;
float: left;
}
formCenterColumn {
/* background: #ff6666; This is for development only */
}
formCenterColumn.ach {
}
formColumnTwo div.fieldContainer a img,#formColumnThree div.fieldContainer a img,#formColumnThree div.compactFieldContainer a img,#formLeftColumn div.fieldContainer a img, #formRightColumn div.fieldContainer a img, #formCenterColumn div.fieldContainer a img {
}
formColumnTwo {
/* background: #ffff99; This is for development only ; Note that I changed the height from 350 to 41v0 for Ruby test*/
}
formColumnThree {
/* background: #ff6666; This is for development only */
}
.compactFieldContainer {
display: block;
float: left;
padding: 10px 10px 0px 10px;
}
formColumnOne {
/* background: #ffff99; This is for development only */
}
formColumnOne ul {
}
ul.addItem {
list-style-image: url('../_assets/_images/add.png');
}
/* Service Location CSS */
serviceLocationContainer {
}
ul.addItem li:hover {
color: #669966;
text-decoration: underline;
cursor: pointer;
}
[placeholder = "###-###-####"], [placeholder = "### - ## - ####"], [placeholder = "#####-####"] {
color: #675845;
}
serviceLocationsLabel {
}
.thinkingContainer {
display: block;
float: left;
padding: 36px 0px 0px 0px;
}
.hideField {
display: none;
}
.showField {
display: block;
}
loginErrorMsg {
}
loginErrorMsg h2 {
}
loginBlockedMsg {
}
loginBlockedMsg h2 {
}
cancelLoginContainer {
}
.cancelLogin {
display: block;
float: left;
margin-left: 40%;
width: 100%;
}
.cancelLogin input {
color: #993300;
}
.cancelLogin input:hover {
color: #675845;
text-decoration: underline;
cursor: pointer;
}
input.deleteIcon {
float: left;
padding-left: 15px;
padding-top: .8em;
}
p.deleteItem {
font-size: .8em;
padding-left: 5px;
}
ul.deleteItem li:hover {
color: #993300;
text-decoration: underline;
cursor: pointer;
}
locationItem {
}
locationItem:hover {
}
locationItem.loc_sel {
}
locationItem p a {
}
locationItem p a:hover {
}
esidSelectionInstructions {
}
/* Tooltip CSS */
.tip {font:1em Arial,Helvetica,sans-serif; font-weight: normal; border:solid 1px #666666; width:250px;
padding:1px; position:absolute; z-index:100; visibility:hidden; color:#FFF;
top:20px; left:90px; background-color:#675845; border-radius: 15px;
/* opacity:0.8; CSS3 - range 0 to 1
-moz-opacity:0.9; Firefox - range 0 to 1
filter:alpha(opacity=90); IE - range 0 to 100 */
}
t1 {width:130px;}
t2 {margin: -1em 0px 0px 100px;}
t3 {width:264px;}
t4 {width:250px; padding: 10px;}
t5 {width:250px; padding: 10px; left:150px;}
t6 {width:230px; text-align: center;}
/*#t1 {width:130px;}
t2 {width:480px;}
t3 {font:bold 14pt verdana,arial,sans-serif; background-color:#ffcccc; layer-background-color:#ffcccc;}*/
/* dialog box */
dialogBox {
/* display: none;*/
z-index: 999;
position: fixed;
background-color: #BF6A30;
border-radius: 15px;
overflow: hidden;
margin: 0px auto;
}
.dialogContent {
background-color: #eee;
border-width: 4px;
border-color: #BF6A30;
border-style: solid;
border-radius: 15px;
padding: 0px 8px 4px 8px;
width: 350px;
/* shaded div */
dialogShade {
}
/* CSS for Security Information */
esidSelectionInstructions {
}
.errorMsg {
position: absolute;
margin-left: -225px;
margin-top: 2em;
font-size: .8em;
color: #993300;
}
.dualFieldContainer {
clear: both;
display: Block;
width: 100%
}
.leftFieldContainer {
padding-left: 10px;
padding-top: 20px;
float: left;
}
.rightFieldContainer {
padding-top: 20px;
}
formCenterColumn.securityInfo {
}
.userIdInstructions {
width: 250px;
padding-bottom: 0px;
margin-bottom: 0px;
}
signatureStyleContainer {
}
.styleOption {
display: block;
float: left;
width: 300px;
padding-top: 15px;
}
s1l {font-family: "Brush Script MT"; font-size: 1.5em; }
s2l {font-family: "Edwardian Script ITC"; font-size: 1.5em;}
s3l {font-family: "Lucida Calligraphy"; font-size: 1.5em; }
s4l {font-family: "Lucida Handwriting"; font-size: 1.5em; }
s5l {font-family: "Mistral"; font-size: 1.5em; }
s6l {font-family: "Comic Sans MS"; font-size: 1.5em; }
permissionsContainer {
}
permissionsContainer input {
}
.authLabel {
display: block;
padding-left: 30px;
width: 300px;
font-size: .75em;
}
.authLabel:hover {
cursor: pointer;
}
digitalSignature{
}
dsl1 {
}
dateSigned{
}
dsl2 {
}
dsl3 {
}
signatoryTitle{
}
Here is the i18N resource en.yml :
en:
hello: "Hello world!"