2

私は、インデックスと約ページを使って、単純なアプリケーションをコーディングしたいです.dbを使わずに、すべてのテキストがビューにあります。しかし、ビューを変更するために私のコントローラメソッドを呼び出すことはできません。シンプルなRuby on Railsアプリケーション

!!! 
%html 
    %head 
    %title Title 
    = stylesheet_link_tag "application" 
    = javascript_include_tag "application" 
    = csrf_meta_tags 
    %body 
    .wrapper 
     = yield 
     .footer 

ホームインデックスビュー:ビュー約

%h2 Index 
%h1 
    This is example page 
%p 
    = link_to "Home", root_path 
    = link_to "About", :controller => "home", :action => "index" 
%p 
    "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." 

:routes.rbを内

%h2 About 
%h1 
    This is about page 
%p 
    = link_to "Home", root_path 
    = link_to "About", :controller => "home", :action => "about" 
%p 
    Lorem ipsum 

ここでは、コントローラ(home_controller.rb)

class HomeController < ApplicationController 

    def index 
    end 

    def about 
    end 

end 

レイアウトであります私はを持っています私は自分のドメインを呼び出すときに、私は私が書く指数、買ってあげる

:ドメイン/ホーム/インデックスを私は

Noルートの一致を取得しない "/ホーム/インデックス"

を[GET]

私が電話すると、それは同じです、どうすれば私のページに電話をかけることができますか? すくいルートは私を与える:

ルート/ {:コントローラ=> "自宅"、:アクション=> "インデックス"}

答えて

2

あなたにもそれらのルートを定義する必要があります。自動的には表示されません。

たとえば、デフォルトで生成されたroutes.rb(最後に)で見つけることができます。

# 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)))' 

コメントを解除し、この、あなたが/home/index/home/aboutにアクセスすることができるはずです。あなたのルートに以下を追加し

+0

root :to => ...ライン上記のファイル:ハンドラ=> [:ERB、:ビルダーを、: coffee::haml]、:formats => [:html]、::ロケール=> [:en、:en]}検索対象:* "/ mnt/_Projects/exapmle2/app/views" wtf?私はこれを持っています – byCoder

+0

あなたは '/ app/views/home/about.html.haml'を持っていますか? –

+0

ofc私は持っている、これは面白いです – byCoder

1

てみテンプレートは 欠落テンプレートホーム/について、{約アプリケーション/失われ

get 'home/index' 
get 'home/about' 
+0

バックスラッシュについては本当ですか? :) –

+0

@Sergio最近、窓で働いてくれてありがとう –

関連する問題