关于在Ruby on Rails中设计博客存在一些错误问题

怪物码

我试图使用回形针将Images包含在我的博客设计中。我不断收到错误消息:ArticlesController#create中的ActionController :: UrlGenerationError没有路由匹配{:action =>“ show”,:controller =>“ articles”}缺少必需的键:[:id]现在,每当我单击提交时按钮创建新文章,并显示“找不到没有ID的文章”。我也尝试通过链接访问显示页面的视图,但我做不到。

提取的来源(第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
罗斯塔

错误提示您:id尝试在中生成商品展示路线时缺少参数ArticlesController

resources :articles在您的在线config/routes文件会产生许多途径的辅助方法,包括article_path为展示途径。默认情况下,此辅助方法需要一个参数-该参数可以转换为上述:id参数。此参数应该是商品ID,或更常见的是商品实例。您需要告诉Rails将用户发送到哪个文章显示页面,对吗?

因此,您需要article_pathcreate操作中将文章实例传递给您的调用update它会出现)。这是您的create操作的重写

def create
  @article = Article.new(article_params)
  @article.save
  redirect_to article_path(@article)
end

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

关于C ++中的数组的一些问题

来自分类Dev

JS中关于OOP的一些基本问题

来自分类Dev

关于setMnemonic的一些问题

来自分类Dev

关于FASM的一些问题

来自分类Dev

关于sipp的一些问题

来自分类Dev

关于Ruby Koans中的about_scope.rb的问题

来自分类Dev

重构Ruby on Rails中的一些模型方法

来自分类Dev

RestClient在Ruby中引发一些错误

来自分类Dev

关于Ruby koans about_classes.rb的问题

来自分类Dev

我有关于 ruby 循环睡眠的问题

来自分类Dev

关于ruby on rails从复选框获取值吗?

来自分类Dev

Ruby中关于Dir []和File.join()的困惑

来自分类Dev

Ruby 文档中关于 puts 的“ios”是什么?

来自分类Dev

关于Redigo和并发的一些问题

来自分类Dev

关于余弦相似度的一些问题

来自分类Dev

关于PHPExcel图表的一些问题

来自分类Dev

木筏:关于只读查询的一些问题

来自分类Dev

java关于一些使用问题?“超级水果”

来自分类Dev

关于体积渲染的一些新手问题

来自分类Dev

关于C语言中的“ goto”的一些问题

来自分类Dev

关于 pthread_create() 的一些问题

来自分类Dev

关于以下代码的一些问题

来自分类Dev

关于EDT和时差的一些问题

来自分类Dev

关于`ngx_palloc`的一些问题?

来自分类Dev

关于我的网站的一些问题

来自分类Dev

关于GC和DisplayCompositor的一些问题

来自分类Dev

关于类类型函数的一些问题

来自分类Dev

需要一些关于结构问题的建议

来自分类Dev

关于Javacard中的SELECT APDU命令的一些问题