Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
808 views
in Technique[技术] by (71.8m points)

ruby-on-rails - #的未定义方法“ article_comments_path”是什么意思? article_new_path(undefined method `article_comments_path' for # Did you mean? articles_new_path)

i am getting an error and i am following ruby on rails guide https://guides.rubyonrails.org/getting_started.html can anyone help me out ?

(我遇到错误,并且正在关注ruby on rails指南https://guides.rubyonrails.org/getting_started.html ,有人可以帮助我吗?)

if you know the answer then please write the file name with prpoper right code.

(如果您知道答案,请使用prpoper正确的代码写文件名。)

when i am attempting to show file then was showing this type of error .

(当我尝试显示文件时,则显示此类错误。)

show.html

(show.html)

'''

(''')

<p>
  <strong>Title:</strong>
  <%= @article.title %>
</p>

<p>
  <strong>Text:</strong>
  <%= @article.text %>
</p>

<h2>Comments</h2>
<% @article.comments.each do |comment| %>
  <p>
    <strong>Commenter:</strong>
    <%= comment.commenter %>
  </p>

  <p>
    <strong>Comment:</strong>
    <%= comment.body %>
  </p>
<% end %>

<h2>Add a comment:</h2>
<%= form_with(model: [ @article, @article.comments.build ], local: true) do |form| %>
  <p>
    <%= form.label :commenter %><br>
    <%= form.text_field :commenter %>
  </p>
  <p>
    <%= form.label :body %><br>
    <%= form.text_area :body %>
  </p>
  <p>
    <%= form.submit %>
  </p>
<% end %>

<%= link_to 'Edit', edit_article_path(@article) %> |
<%= link_to 'Back', articles_path %>
<h1><%= link_to 'new_Article', new_article_path %></h1>

'''

(''')

comment controller

(评论控制器)

'''

(''')

class CommentsController < ApplicationController
  def create
    @article = Article.find(params[:article_id])
    @comment = @article.comments.create(comment_params)
    redirect_to article_path(@article)
  end

  private
    def comment_params
      params.require(:comment).permit(:commenter, :body)
    end
end

'''

(''')

index.html.erb

(index.html.erb)

'''

(''')

<center>

<table border="1pt">
  <tr>
    <th>Title</th>
    <th>Text</th>
    <th colspan="3">id</th>
  </tr>

  <% @articles.each do |article| %>
    <tr>
      <td><%= article.title %></td>
      <td><%= article.text %></td>
      <td><%= article.id %></td>
      <td><%= link_to 'Show', article_path(article) %></td>
      <td><%= link_to 'Edit', edit_article_path(article) %></td>
      <td><%= link_to 'Destroy', article_path(article),
              method: :delete,
              data: { confirm: 'Are you sure?' } %>
      </td>
    </tr>
  <% end %>
</table>
<h1><a href="http://localhost:3000/articles/new">new article</a>
</h1>
</center>

'''

(''')

article_controller

(article_controller)

'''

(''')

class ArticlesController < ApplicationController
    def index
      @articles = Article.all
    end

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

    def new
        @article =Article.new
    end

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

    def create
      @article = Article.new(article_params)

      if @article.save
        flash[:notice] = "Article was submitted succsefully"
        redirect_to(@article) 
       else
        render 'new'
      end
    end

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

        if @article.update(article_params)
            redirect_to @article
        else
            render 'edit'
        end
    end

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

        redirect_to articles_path
    end

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

'''

(''')

i am getting an error and i am following ruby on rails guide https://guides.rubyonrails.org/getting_started.html can anyone help me out ?

(我遇到错误,并且正在关注ruby on rails指南https://guides.rubyonrails.org/getting_started.html ,有人可以帮助我吗?)

if you know the answer then please write the file name with prpoper right code.

(如果您知道答案,请使用prpoper正确的代码写文件名。)

when i am attempting to show file then was showing this type of error .

(当我尝试显示文件时,则显示此类错误。)

  ask by vishal jat translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...