設置我的config.ru和gemfile後,我的帖子不再想工作。Sinatra沒有方法錯誤
首先,我必須在我的main.rb中有我的DataMapper.setup,並且我無法在我的irb中運行任何DataMapper方法。
其次,每當我通過POST提交表單的一些數據保存到我的分貝西納特拉返回與...
NoMethodError at/
undefined method `each' for "asdfasdf":String
file: resource.rb
location: attributes=
line: 329
main.rb的
#Required Gems
require 'sinatra'
require 'data_mapper'
DataMapper.setup(:default, ENV['DATABASE_URL'] || 'postgres://host:[email protected]
/blog_development')
#Database Migration
class Code
include DataMapper::Resource
property :id, Serial
property :code, String, :required => true
property :translation, String
property :completed_at, DateTime
end
#Set up Migration
DataMapper.finalize
#Routes Section
get '/' do
@codes = Code.all
slim :index
end
#Get Code
get '/:code' do
@morse_code = params[:code]
slim :code
end
#POST Code
post '/' do
@code = Code.create params[:code]
redirect to('/')
end
的Gemfile
source :rubygems
gem "sinatra", "~> 1.3.3"
gem "data_mapper", "~> 1.2.0"
gem "slim", "~> 1.3.4"
gem "dm-postgres-adapter", "~> 1.2.0"
config.ru
require 'bundler'
Bundler.require
require './main'
DataMapper.setup(:default, ENV['DATABASE_URL'] || 'postgres://host:[email protected]
/blog_development')
run Sinatra::Application
請注意,asdfasdf是我在提交前放入表單的輸入框中的文本。
對於萬一有人願意住測試回購... https://github.com/thejourneydude/morsecode
和''asdfasdf「:String'來自哪裏? – shime
這是我在提交表單之前在表單的輸入框中輸入的文本。 – jason328
我幾乎可以肯定你在做數據映射器的問題。爲什麼你不能在irb中使用它?什麼是'resource.rb'和329行是什麼?我也建議你從這裏刪除你的數據庫憑證;) – shime