ruby-on-rails 错误参数丢失或值为空:轨道中的物品7

iaqfqrcu  于 2023-05-02  发布在  Ruby
关注(0)|答案(1)|浏览(103)

articles_controller:我在Rails上遇到了一个小问题,我在article_params方法中遇到了错误。我已经看了几个其他的解决问题的办法,但他们不帮助我。这是我的代码。

class ArticlesController < ApplicationController

def index
    @articles = Article.all
end

def show
    @article = Article.find(params[:id])
end

def new
    @article = Article.new
end

def create
    # render plain: params[:article].inspect
    @article = Article.new (article_params)
    if  @article.save
        redirect_to @article
    else
        render action: 'new'
    end
    
end

def edit
    @article = Article.find(params[:id])
end

def update
    @article = Article.find (params[:id])
    if @article.update(article_params)
        redirect_to @article
    else
        render action: 'edit'
    end
end

def destroy
  @article = Article.find(params[:id])
  @article.destroy (article_params)
end

private

def article_params
    params.require(:article).permit(:title, :text)
    
end

结束
index.html.erb:我写了button_to helper,但是我得到了这个错误

<h3>The articles list</h3>

<% @articles.each do |article|%>
    <h4><%= article.title%></h4>
    <p><%= article.text%></p>
    <p><%=  link_to 'Show', article_path(article)%></p>
    <p><%=  link_to 'Edit', edit_article_path(article)%></p>
    <p><%= button_to 'Delete',  article_path(article), data: {turbo: false}, method: :delete%></p>
    <hr/>
    <%= params.inspect%>
<% end %>
1bqhqjot

1bqhqjot1#

这一行:

@article.destroy (article_params)

应该只是

@article.destroy

相关问题