我試圖用回形針將圖片添加到我的博客設計中。我不斷收到錯誤: ArticlesController中的ActionController :: UrlGenerationError#create 沒有路由匹配{:action =>「show」,:controller =>「articles」}缺少必需的鍵:[:id] 現在,在提交按鈕上創建一篇新文章,它會顯示「找不到沒有ID的文章」。我嘗試通過鏈接訪問顯示頁面的視圖,但我無法訪問。在Ruby on Rails中設計博客時出現了一些錯誤問題
提取的源(左右線#30):
這裏是我的文章控制器
class ArticlesController < ApplicationController
def index
@articles = Article.all
end
def show
@article = Article.find(params[:id])
@comment = Comment.new
@comment.article_id = @article.id
end
def new
@article = Article.new
end
def create
@article = Article.new(article_params)
@article.save
redirect_to article_path
end
def edit
@article = Article.find(params[:id])
end
def destroy
@article = Article.find(params[:id])
@article.destroy
redirect_to articles_path
end
def update
@article = Article.find(params[:id])
@article.update(article_params)
flash.notice = "Article '#{@article.title}' Updated!"
redirect_to article_path
end
def article_params
params.require(:article).permit(:title, :body, :tag_list, :image)
end
end
這裏是我的文章助手:
module ArticlesHelper
def article_params
params.require(:article).permit(:title, :body, :tag_list, :image)
end
end
這裏是我的文章/ show.html .erb
<h1><%= @article.title %></h1>
<p>
Tags:
<% @article.tags.each do |tag| %> <%= link_to tag.name, tag_path(tag) %>
<% end %>
</p>
<% if @article.image.exists? %>
<p><%= image_tag @article.image.url %></p>
<% end %>
<p><%= @article.body %></p>
<h3>Comments (<%= @article.comments.size %>)</h3>
<%= render partial: 'articles/comment', collection: @article.comments %>
<%= render partial: 'comments/form' %>
<%= link_to "<< Back to Articles List", articles_path %>
<%= link_to "delete", article_path(@article), method: :delete, data: {confirm: "Really delete the article?"} %>
<%= link_to "edit", edit_article_path(@article) %>
這裏是我的路線文件
TheBlog::Application.routes.draw do
root 'static_pages#home'
get 'help' => 'static_pages#help'
get 'about' => 'static_pages#about'
get 'contact' => 'static_pages#contact'
get 'signup' => 'users#new'
get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
get 'article' => 'articles#show'
resources :users
resources :articles do
resources :comments
end
resources :tags
end
這是在一個測試或從運行開發服務器? – AJcodez 2014-10-30 23:25:42
請包括您的ArticlesController創建代碼 – 2014-10-31 00:59:03