0
我想要的是如果用戶登錄,他會被重定向到頁面,以便他可以創建一篇新文章。但現在,他被重定向到所有類別的頁面。當我註冊時,我想重定向到文章/新頁面,但重定向到類別/索引
這裏是routes.rb中
的routes.rb
Rails.application.routes.draw do
root 'categories#index'
resources :articles do
member do
resources :comments, only: :create
end
end
resources :categories
devise_for :users
get 'auth/login'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
這裏是分類索引頁。 分類/ INDEX
<p id="notice"><%= notice %></p>
<h1>Categories</h1>
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Body</th>
<th>Published</th>
<% if(current_user.admin?) %>
<th colspan="3">Actions</th>
<% else %>
<th>Actions</th>
<% end%>
</tr>
</thead>
<tbody>
<% @categories.each do |category| %>
<tr>
<td><%= category.title %></td>
<td><%= category.body %></td>
<td><%= category.published%></td>
<% if(current_user.admin?) %>
<td><%= link_to 'Show', category, class: 'btn btn-default' %></td>
<td><%= link_to 'Edit', edit_category_path(category), class: 'btn btn-primary' %></td>
<td><%= link_to 'Destroy', category, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' %></td>
<% else %>
<td><%= link_to 'Show', category, class: 'btn btn-default' %></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
<%= paginate @categories %>
<br>
<%if current_user.admin? %>
<%= link_to 'New Category', new_category_path %>
<% end %>
@Debashish感謝您的幫助,但現在我得到like-- NoMethodError錯誤在設計::對於#顯示錯誤------- <%= simple_form_for(resource,as:resource_name,url:session_path(resource_name))do | f | %> –