【发布时间】:2017-07-02 05:31:09
【问题描述】:
您好,我正在尝试使用 ruby、sinatra、ActiveRecord 和 mysql 建立一个数据库来存储电子邮件。关于我做错了什么的任何建议?我试图将其输出到只有我可以看到的单独页面,然后使用 hostgator 上的 url 将其发布。
require 'sinatra'
require 'activerecord'
# require 'sinatra-activerecord'
get '/' do
erb :index
end
def save_email (email)
file.print(email)
end
get '/email' do
params[:email]
# # redirect '/'
end
post '/email' do
params[:email]
@email = params[:email]
erb :email, :locals => {:email => params[:email]}
end
# Change the following to reflect your database settings
ActiveRecord::Base.establish_connection(
adapter: 'mysql', # or 'postgresql'
host: 'localhost',
database: 'Stored_Emails',
)
class Stored_Emails < Sinatra::Application
end
class Stored_Emails < ActiveRecord::Base
end
ActiveRecord::Migration.create_table :email do |t|
t.string :emails
end
create_table :emails, force: true do |t|
t.string :email
t.belongs_to :email, index: true
end
get '/email' do
params[:email].all
end
【问题讨论】:
-
这里有什么问题?这是相当混乱的代码。
-
是的,抱歉,我查看了太多资源,并认为我组合了错误的语法。我无法启动数据库,因为我遇到了错误。主要错误是我缺少一个参数@tadman
-
错误在解释您的问题时有不可估量的帮助,因此您需要传达这些错误是什么以及它们所指的行。
-
ok ernel_require.rb:55:in `require' 是它在终端中所说的,但我很难破译它。
-
一切直到 ActiveRecord::Base。是正确的
标签: mysql ruby activerecord sinatra