我創建了一個表單來創建文章,但我只能在索引頁上看到已發佈的文章,而且我無法查看單個文章。無法顯示Ruby on Rails上的文章?
每次點擊索引上單個文章的「顯示」時,它都會打開一個空白頁面,其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_controller.rb:
# GET /articles/1
# GET /articles/1.json
def show
@article = Article.find(params[:id])
end
潰敗es.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' –
@LuisLago我發佈你的routes.rb在你的問題。您可以在下次編輯問題而不是將其粘貼到評論中;否則很難閱讀。 –
謝謝,我會記住,下次 – LuisLago