我想知道是否有人可以解決我遇到的一些問題?我創建一個rails應用程序:開始使用Ruby on Rails遇到問題
rails myapp -d mysql
cd myapp
haml --rails .
rake db:create:all
然後我想用一個mysql客戶端來創建表。讓我們說用戶和客戶。一位顧客也是一個用戶,所以你有模式是這樣的:
users
----------------
id int, not null, primary key, auto increment
first_name varchar(50) not null
last_name varchar(50) not null
email varchar(50) not null unique
password varchar(50) not null
created_at datetime not null
updated_at datetime not null
customers
----------------
id int, not null, primary key, auto increment
user_id int, unique
-- some other stuff that is customer specific
什麼軌腳本命令我需要運行得到的模型,視圖和控制器創建並在我的Rails應用程序完全填滿了呢?我嘗試這樣做:
ruby script/generate scaffold user
ruby script/generate scaffold customer
它創建的文件,但該機型是空的:
class User < ActiveRecord::Base
end
什麼交易?另外,我想創建一個管理部分來管理內容。我想通了,我需要添加路由那些:
map.namespace :admin do |admin|
admin.resources :users
admin.resources :customers
end
還有什麼,我需要得到管理部分回事? 另外這裏是我運行紅寶石/寶石的版本:
ruby 1.8.6
rails 2.3.5 & 2.3.2 <- I'm using 2.3.2 because haml
wasn't working (or some other plugin) with 2.3.5
haml 2.2.15
rspec 1.2.9 <- I saw from another thread that I might need
this when creating an adminstration section (rspec_controller etc)
好的。這很好。模型應該是空的,這很好,但讓我澄清一些事情:當我去:http:// localhost:3000 /用戶/新我得到「新用戶」和一個創建按鈕,但沒有文本框等我是什麼做錯了? – DJTripleThreat
我以前告訴過你。爲了獲得填充模型屬性的視圖,您需要將屬性傳遞給腳手架調用。 –
是的,我讀過你說的話。我只是不明白爲什麼rails不能通過讀取db或schema.rb來填充模型。它可以做其他所有事情,爲什麼不呢?我之前運行過這個命令並獲得了預期的結果,但我不應該在命令行中輸入所有這些命令。 – DJTripleThreat