Saya membuat formulir untuk membuat artikel, tetapi saya hanya dapat melihat artikel yang diterbitkan di halaman indeks, dan saya tidak dapat melihat artikel satu per satu.
Setiap kali saya mengeklik 'tampilkan' untuk satu artikel di indeks, halaman kosong akan terbuka dengan URL seperti localhost:3000/articles.1
, bukan localhost:3000/articles/1
.
Saya tidak tahu apa yang salah dengan kodenya, ini mirip dengan kode yang saya miliki untuk membuat dan mengedit artikel sebagai admin dan berfungsi di sana, tetapi saya terus mendapatkan kesalahan ini.
Berikut kodenya:
tampilan/artikel/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 %>
tampilan/artikel/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 %>
artikel_controller.rb:
# GET /articles/1
# GET /articles/1.json
def show
@article = Article.find(params[:id])
end
rute.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
mu - person Зелёный   schedule 11.12.2013