Rails101
hi,我又來發問了
我購買了一本XD大的書
遇到了問題...
Routing Error
Try running rake routes for more information on available routes.
在產生pages controller
[~/projects/forum_demo] (master) $ rails g controller pages
create app/controllers/pages_controller.rb
invoke erb
create app/views/pages
invoke test_unit
create test/functional/pages_controller_test.rb
invoke helper
create
invoke
create
app/helpers/pages_helper.rb
test_unit
test/unit/helpers/pages_helper_test.rb
這個步驟好像出現了問題
是在終端機打上“rails g controller pages” 嗎?
$
號後面就是在終端機輸入的命令。
那前面的那一段呢。。。
create app/controllers/pages_controller.rb
invoke erb
create app/views/pages
invoke test_unit
create test/functional/pages_controller_test.rb
invoke helper
create
invoke
create
app/helpers/pages_helper.rb
test_unit
test/unit/helpers/pages_helper_test.rb
後面這段是什麼意思...
就是打下去之後出現了以上這些東西,你打打看就知道了
#2樓
產生了一些檔案 view, helper, test
可以看看這個:
http://guides.ruby.tw/rails3/getting_started.html#7-4
http://ihower.tw/rails3/firststep.html
我顯示的東西跟上面的東西不一樣。。
那我怎麼會出現...
Routing Error
Try running rake routes for more information on available routes.
我找了好久的問題
那你打 rake routes
出現的是甚麼?以及可以貼出你的 routes.rb
嗎?
因為你沒有在 controller 上加入 class
還有你要記得在config/routes.rb 裡加入
resources :pages
所以他才會出現routing error
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
routes.rb
ForumDemo::Application.routes.draw do
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end
# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => 'welcome#index'
root :to => "pages#welcome"
# See how all your routes lay out with "rake routes"
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id))(.:format)'
end
#8樓 @queenbyer 明天可以去 Rails Tuesday 問大神們 XD
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /Users/pleasuresuki/.rvm/rubies/ruby-1.9.3-p125/bin/ruby
-b, [--builder=BUILDER] # Path to a application builder (can be a filesystem path or URL)
-m, [--template=TEMPLATE] # Path to an application template (can be a filesystem path or URL)
[--skip-gemfile] # Don't create a Gemfile
[--skip-bundle] # Don't run bundle install
-G, [--skip-git] # Skip Git ignores and keeps
-O, [--skip-active-record] # Skip Active Record files
-S, [--skip-sprockets] # Skip Sprockets files
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
# Default: sqlite3
-j, [--javascript=JAVASCRIPT] # Preconfigure for selected JavaScript library
# Default: jquery
-J, [--skip-javascript] # Skip JavaScript files
[--dev] # Setup the application with Gemfile pointing to your Rails checkout
[--edge] # Setup the application with Gemfile pointing to Rails repository
-T, [--skip-test-unit] # Skip Test::Unit files
[--old-style-hash] # Force using old style hash (:foo => 'bar') on Ruby >= 1.9
Runtime options:
-f, [--force] # Overwrite files that already exist
-p, [--pretend] # Run but do not make any changes
-q, [--quiet] # Supress status output
-s, [--skip] # Skip files that already exist
Rails options:
-h, [--help] # Show this help message and quit
-v, [--version] # Show Rails version number and quit
Description:
The 'rails new' command creates a new Rails application with a default
directory structure and configuration at the path you specify.
You can specify extra command-line arguments to be used every time
'rails new' runs in the .railsrc configuration file in your home directory.
Note that the arguments specified in the .railsrc file don't affect the
defaults values shown above in this help message.
Example:
rails new ~/Code/Ruby/weblog
This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
See the README in the newly created application to get going.
呃...這是 rails new 的命令幫助訊息?所以還是 Route 錯誤嗎?還是不能創一個新的 app?
產生 rails g controller pages 跑出來的訊息。_。
你應該要先建立一個專案,再來建立控制器。
在終端機輸入:
rails new forum_demo
建立一個新專案叫做 forum_demo
cd forum_demo
切換到專案目錄
rails g controller pages
建立控制器
我是依照步驟走的,但是,還是出現那個。。。
#14樓 @queenbyer 如果不是在一個 rails 專案目錄下: rails g controller pages ,就會跳出上面那一大串叫你先建一個新的 Rails 專案。