469fddeb62ffc22d28eac9e4ffc8f324

Rails101

2012-04-16 14:00:19 +0800queenbyerRuby on Rails 節點 中發起
最後由 匿名 於2012-04-17 18:56:37 +0800回應 , 252次閱讀

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” 嗎?

截至 2012-04-17 18:56:37 +0800,共收到 15 條回應
D41d8cd98f00b204e9800998ecf8427e
匿名 1樓, 於2012-04-16 14:32:55 +0800回應

$ 號後面就是在終端機輸入的命令。

469fddeb62ffc22d28eac9e4ffc8f324
queenbyer 2樓, 於2012-04-16 14:47:14 +0800回應

那前面的那一段呢。。。

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

後面這段是什麼意思...

36b1f565fc83d9b67588123f2171b896
chitsaou 3樓, 於2012-04-16 14:48:41 +0800回應

就是打下去之後出現了以上這些東西,你打打看就知道了

D41d8cd98f00b204e9800998ecf8427e
匿名 4樓, 於2012-04-16 15:16:34 +0800回應

#2樓
產生了一些檔案 view, helper, test
可以看看這個:
http://guides.ruby.tw/rails3/getting_started.html#7-4
http://ihower.tw/rails3/firststep.html

469fddeb62ffc22d28eac9e4ffc8f324
queenbyer 5樓, 於2012-04-16 15:32:24 +0800回應

我顯示的東西跟上面的東西不一樣。。

那我怎麼會出現...

Routing Error

Try running rake routes for more information on available routes.

我找了好久的問題

36b1f565fc83d9b67588123f2171b896
chitsaou 6樓, 於2012-04-16 15:52:12 +0800回應

那你打 rake routes 出現的是甚麼?以及可以貼出你的 routes.rb 嗎?

Ab4c0c1855a73a65d159118da1a2614c
SammyLinTw 7樓, 於2012-04-16 15:52:56 +0800回應

因為你沒有在 controller 上加入 class
還有你要記得在config/routes.rb 裡加入
resources :pages
所以他才會出現routing error

469fddeb62ffc22d28eac9e4ffc8f324
queenbyer 8樓, 於2012-04-16 20:50:38 +0800回應

#6樓

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

D41d8cd98f00b204e9800998ecf8427e
匿名 9樓, 於2012-04-16 23:08:20 +0800回應

#8樓 @queenbyer 明天可以去 Rails Tuesday 問大神們 XD

469fddeb62ffc22d28eac9e4ffc8f324
queenbyer 10樓, 於2012-04-17 14:30:25 +0800回應

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.

D41d8cd98f00b204e9800998ecf8427e
匿名 11樓, 於2012-04-17 15:24:05 +0800回應

呃...這是 rails new 的命令幫助訊息?所以還是 Route 錯誤嗎?還是不能創一個新的 app?

469fddeb62ffc22d28eac9e4ffc8f324
queenbyer 12樓, 於2012-04-17 16:49:30 +0800回應

產生 rails g controller pages 跑出來的訊息。_。

D41d8cd98f00b204e9800998ecf8427e
匿名 13樓, 於2012-04-17 17:04:36 +0800回應

你應該要先建立一個專案,再來建立控制器。
在終端機輸入:
rails new forum_demo 建立一個新專案叫做 forum_demo
cd forum_demo 切換到專案目錄
rails g controller pages 建立控制器

469fddeb62ffc22d28eac9e4ffc8f324
queenbyer 14樓, 於2012-04-17 18:48:26 +0800回應

我是依照步驟走的,但是,還是出現那個。。。

D41d8cd98f00b204e9800998ecf8427e
匿名 15樓, 於2012-04-17 18:56:37 +0800回應

#14樓 @queenbyer 如果不是在一個 rails 專案目錄下: rails g controller pages ,就會跳出上面那一大串叫你先建一個新的 Rails 專案。

需要 登入 後方可回應,如果你還沒有帳號按這裡 註冊