Я создал форму для создания статей, но я могу видеть только опубликованные статьи на главной странице и не могу видеть отдельные статьи.
Каждый раз, когда я нажимаю «показать» для отдельной статьи в индексе, открывается пустая страница с 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 %>
article_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