ฉันสร้างแบบฟอร์มเพื่อสร้างบทความ แต่สามารถดูได้เฉพาะบทความที่เผยแพร่ในหน้าดัชนีเท่านั้น และฉันไม่สามารถดูแต่ละบทความได้
ทุกครั้งที่ฉันคลิก 'แสดง' สำหรับแต่ละบทความในดัชนี จะมีการเปิดหน้าว่างที่มี URL เช่น localhost:3000/articles.1
แทนที่จะเป็น localhost:3000/articles/1
ฉันไม่รู้ว่ามีอะไรผิดปกติกับโค้ด มันคล้ายกับโค้ดที่ฉันมีสำหรับสร้างและแก้ไขบทความในฐานะผู้ดูแลระบบ และมันใช้งานได้ที่นั่น แต่ฉันได้รับข้อผิดพลาดนี้อยู่เรื่อยๆ
นี่คือรหัส:
มุมมอง/บทความ/show.html.erb:
<h1><%= @article.name %></h1>
<%= @article.content %>
<%= image_tag @article.photo.url(:small) %>
<p>Tags: <%= raw article.tag_list.map { |t| link_to t, tag_path(t) }.join(', ') %></p>
<%= link_to 'Back', noticias_path %>
มุมมอง/บทความ/index.html.erb:
<% @articles.each do |article| %>
<div>
<h2><%= article.name %></h2>
<%= article.content %>
<p><%= link_to 'Show', noticias_path(article) %></p>
<p>Tags: <%= raw article.tag_list.map { |t| link_to t, tag_path(t) }.join(', ') %></p>
</div>
<% end %>
Articles_Controller.rb:
# GET /articles/1
# GET /articles/1.json
def show
@article = Article.find(params[:id])
end
เส้นทาง.rb:
Blog::Application.routes.draw do
root to: 'welcome#index'
get 'tags/:tag', to: 'noticias#index', as: :tag
get "noticias/index"
get "dashboard/index"
get "/sitemap" => "sitemap#index", :as => :sitemap, :defaults => {:format => :xml}
match '/noticias', to: 'noticias#index', via: 'get'
get 'login', to: 'sessions#new', as: 'login'
get 'logout', to: 'sessions#destroy', as: 'logout'
resources :users
resources :sessions
namespace :admin do
get '', to: 'dashboard#index', as: '/'
resources :noticias
end
end
routes.rb
ของคุณ - person Зелёный   schedule 11.12.2013