私が初めてアプリに工夫を使用していますが、私は理解してカントの奇妙な問題を抱えていて、最大混入しますすべての登録、ユーザーサインアップなどをセットアップしてください。すべて正常に動作します。私のアプリケーションヘッダでは、私は私のnav(現在は空である)メニューでログを持つ部分を持っているなど、サインアウト:工夫リンク/ルートは非工夫モデル
_header.html.erb
<div class='topbar'>
<div class='container'>
<%= link_to 'My app', root_path, :class => 'brand' %>
<div class='nav'>
</div>
<%= render 'layouts/user_options' %>
</div>
</div>
_user_options.html.erb
<ul class='user-options'>
<% if user_signed_in? %>
<li><%= link_to "Signed in as #{current_user.username}", '#' %></li>
<li><%= link_to "Sign out", destroy_user_session_path, :method => :delete %></li>
<% else %>
<li><%= link_to "Sign up", new_user_registration_path %></li>
<li><%= link_to "Sign in", new_user_session_path %></li>
<% end %>
</ul>
私が使用している場合今、私は、ナビゲーションメニューへの最初のリンクを追加してい:
<%= link_to 'Tasks', '/tasks/index' %>
すべて結構です。しかし、私は使用している場合:
<%= link_to 'Tasks', :controller => 'tasks', :action => 'index' %>
ときIこのような「サインイン」などの工夫リンクのいずれかをクリックして、私はコメントの要求によって
'No route matches {:controller=>"devise/tasks"}'
を取得し、ここでrake routes:
タスクの出力があります:TOP =>ルート=>環境 (--traceでタスクを実行することにより、完全なトレースを参照してください) のMacBook-ProのドO:dearsherpaオスカー$バンドルexecがすくいルート
tasks_index GET /tasks/index(.:format) {:controller=>"tasks", :action=>"index"}
tasks_show GET /tasks/show(.:format) {:controller=>"tasks", :action=>"show"}
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
root / {:controller=>"pages", :action=>"home"
、ここではルートです。 rb:
get "tasks/index"
get "tasks/show"
devise_for :users
root :to => 'pages#home'
なぜですか?私が間違っていることは何ですか?
編集2:ちなみに、私はそのことを忘れてTask belongs_to User
、Userモデルはdeviseによって生成されています。おそらくこれが原因です。/user/id/tasks /なしで/ tasks/indexにアクセスできませんか?
編集:代わりに、そのコントローラの「取得」路線の私のルート・ファイル内のタスクを、と私は<%= link_to 'Tasks', :controller => 'tasks', :action => 'index' %>
をクリックすると、今ではshowアクションに私を取ります。もっと奇妙なもの、私はリソースを使用してみました。明らかに私のルートには何かが本当に間違っています。
run:結果をここにコピーしてコピーしてください。 – daniel
routes.rbからコードを投稿し、 'rake routes'を実行できますか? – stephenmurdoch
完了、私は自分の質問を編集しました –