2

作成した demo_app 用の 3 つのリソースがあります。ホームページを作成しましたが、ホームページのリンクを配置して、3 つのリソースにリンクしたいと考えました。コードを出しました

<%= link_to 'users', @user %> | 
<%= link_to 'microposts', @micropost %> |
<%= link_to 'task', @task %> |

ホームページにリンクが表示されますが、機能しません

routes.rb ファイル

DemoApp::Application.routes.draw do
      get "static_pages/home"

      resources :tasks

      resources :microposts

      resources :users

      root :to => 'static_pages#home'
    end

私がやりたいのは、ここのようなこれらのそれぞれのインデックスページへのリンクです

<h1>Listing tasks</h1>

<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Status</th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>

  <tbody>
    <% @tasks.each do |task| %>
      <tr>
        <td><%= task.name %></td>
        <td><%= task.status %></td>
        <td><%= link_to 'Show', task %></td>
        <td><%= link_to 'Edit', edit_task_path(task) %></td>
        <td><%= link_to 'Destroy', task, method: :delete, data: { confirm: 'Are you sure?' } %></td>
      </tr>
    <% end %>
  </tbody>
</table>

<br>

<%= link_to 'New Task', new_task_path %>

また、ホームページに戻るリンクもあります。すみません、これはファンキーな質問ですか?

4

4 に答える 4

0

あなたはそれを試すことができます。

<%= link_to 'users', :controller =>"user" %>
<%= link_to 'microposts', :controller =>"micropost" %>
<%= link_to 'task', :controller => "task" %>

link_toによる参照

于 2013-08-27T01:07:58.920 に答える