0

私はこのチュートリアルを行っています:http ://edgeguides.rubyonrails.org/getting_started.html 私が言及することの1つは、チュートリアルとは異なるバージョンのRailsを使用していると思うことです。私はバージョン2.3.14を使用しています。Linuxシステムで作業しています。私はこのようにrailsプロジェクトを設定しました:

rails myproject

チュートリアルで述べたように、多くのディレクトリとファイルを設定します(ただし、チュートリアルではわずかに異なるコマンドを使用します)

次に、次のようにCOntrollerとViewを作成して、最初のアプリをセットアップしました。

ruby script/generate controller welcome index

これにより、プロジェクトのアプリディレクトリ内のコントローラーとビューのサブディレクトリにファイルが作成されました。つまり、viewsディレクトリにファイルindex.html.erbがあることを知っています。

次に、サーバーをテストしたかっただけです。

ruby script/server

次に、ブラウザでlocalhost:3000に移動し、パブリックディレクトリのindex.htmlファイルに移動しました。

これは物事がうまくいかないところです。viewsサブディレクトリのindex.html.erbファイルに移動したい。そこで、configに移動し、routes.rbファイルを開いて編集しました。以下は私の編集したファイルです:

ActionController::Routing::Routes.draw do |map|
  # The priority is based upon order of creation: first created -> highest priority.

  # Sample of regular route:
  #   map.connect 'products/:id', :controller => 'catalog', :action => 'view'
  # Keep in mind you can assign values other than :controller and :action

  # Sample of named route:
  #   map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
  # This route can be invoked with purchase_url(:id => product.id)

  # Sample resource route (maps HTTP verbs to controller actions automatically):
  #   map.resources :products

  # Sample resource route with options:
  #   map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }

  # Sample resource route with sub-resources:
  #   map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller

  # Sample resource route with more complex sub-resources
  #   map.resources :products do |products|
  #     products.resources :comments
  #     products.resources :sales, :collection => { :recent => :get }
  #   end

  # Sample resource route within a namespace:
  #   map.namespace :admin do |admin|
  #     # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
  #     admin.resources :products
  #   end

  # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
   map.root :controller => "welcome#index"#I CHANGED THIS LINE

  # See how all your routes lay out with "rake routes"

  # Install the default routes as the lowest priority.
  # Note: These default routes make all actions in every controller accessible via GET requests. You should
  # consider removing or commenting them out if you're using named routes and resources.
  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
end

ファイルに変更を加えたのは1つだけです。私がしたのは、行のコメントを外すことだけでした

map.root :controller => "welcome#index"

そしてそれを私のindex.html.erbファイルに向けます(少なくともそれは私がやっていることだと思います)。サーバーを再起動しても、index.html(パブリックディレクトリ内)に移動します。そこで、ファイルを削除しました。サーバーを強制終了し、再起動しました。エラーメッセージが表示されます。index.html.erbファイルを読み取ることができません。これを修正するのに助けが欲しいです。

4

2 に答える 2

2

このバージョンのRailsガイドをお試しください:http://guides.rubyonrails.org/v2.3.11/

ただし、学習を開始するには、より新しいバージョンのRails(現在は約3.2)を使用することを強くお勧めします。時間と労力を節約できる可能性があります。

于 2013-01-19T14:08:41.747 に答える
2

rails2.xとrails3.xにはいくつかの大きな違いがあります。edgerailsチュートリアルに従っている場合、それは3.xです。 新しいバージョンのrailsをインストールします。そうすれば、チュートリアルの例に従って問題が発生することはありません。

編集:実際、インストール手順はチュートリアル自体にあります。ruby 1.9のインストールで問題が発生した場合は、rubyのバージョンを管理するため のrbenvが好きです。RVMは、おそらくこのためのより一般的なツールです。

于 2013-01-19T14:04:32.617 に答える