开发者

first application on Ruby on Rails

im begginer in RoR. help me please. i use windows xp, ruby 1.9.2, sqlite 3.7.5 it r my steps for creating new.


  1. install ruby
  2. gem install rails
  3. rails new C:\tm\test
  4. sqlite3.dll, sqlite3.exe
  5. gem install sqlite3-ruby
  6. in database.yml:

    development: adapter: sqlite3 dbfile: db/test.db

  7. C:\tm\test>sqlite3 -init db.sql test.db
  8. rails generate model Article
  9. rails generate controller Article
  10. in test\app\controllers\article_controller.rb: class ArticleController < ApplicationController scaffold :article end
  11. rails server in Firefox http://localhost:3000/article

and have trouble on page: ArgumentError No database file specified. Missing argument: database but i must seeinterface for work with table

in cmd after i see: ArgumentError (No database file specified. Missing argument: database):


in cmd after: 开发者_C百科rails generate scaffold Article Article


i spend this: Missing type for attribute 'Article'. Example: 'Article:string' where string is the type. help me please


It's now database in YML, not dbfile anymore. Try with the following yml in database.yml:

development:
  adapter: sqlite3
  database: db/test.db

Here is a the guide to configure the database on rubyonrails.org.


The first answer is the correct one. If you are scraping your code and need a test start off doing something like this.

#!/usr/bin/env ruby
# Hyra Power
# 11/24/15

require 'active_record'

# ActiveRecord::Base.logger = Logger.new(STDERR)
# ActiveRecord::Base.colorize_logging = false

ActiveRecord::Base.establish_connection(
    :adapter => "sqlite3",
    :database  => ":memory:"
)

ActiveRecord::Schema.define do

    create_table :pages do |table|
        table.column :url, :string, :null => false
        table.column :title, :string
        table.column :content_type, :string
        table.column :last_modified, :datetime
        table.column :error, :string
    end

    create_table :links do |table|
        table.column :from_page_id, :integer, :null => false
        table.column :to_page_id, :integer, :null => false
        table.column :count, :integer

    end

end

class Page < ActiveRecord::Base
    has_many :links
end

class Link < ActiveRecord::Base
    belongs_to :page
end

Test this script and then move on from there. Hope this helps anyone new.


i used: rake db: migrate. and i see this:


rake aborted! No database file specified. Missing argument: database

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜