Last Updated
Viewed 14 Times

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 ? if you know the answer then please write the file name with prpoper right code.

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

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

'''

<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

'''

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 ? if you know the answer then please write the file name with prpoper right code.

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

My user.rb file consists of

class User < ActiveRecord::Base
  attr_accessor :remember_token
  before_save { self.email = email.downcase }
  validates :name,  presence: true, length: { maximum: 50 }
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  validates :email, presence: true, length: { maximum: 255 },
                    format: { with: VALID_EMAIL_REGEX },
                    uniqueness: { case_sensitive: false }

  has_secure_password 
  validates :password, presence: true, length: { minimum: 6 }

  # Returns the hash digest of the given string.
  def User.digest(string)
    cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
                                              BCrypt::Engine.cost
    BCrypt::Password.create(string, cost: cost)
  end

  # Returns a random token.
  def User.new_token
    SecureRandom.urlsafe_base64
  end

  # Remembers a user in the database for use in persistent sessions.
  def remember
    self.remember_token = User.new_token
    update_attribute(:remember_digest, User.digest(remember_token))
 end

  # Forgets a user.
  def forget
    update_attribute(:remember_digest, nil)
  end

  # Returns true if the given token matches the digest.
  def authenticated?(remember_token)
    return false if remember_digest.nil?
    BCrypt::Password.new(remember_digest).is_password?(remember_token)
  end
end

i get the errors

ERROR["test_authenticated?_should_return_false_for_a_user_with_nil_digest", UserTest, 2015-06-01 21:01:42 +0000]
 test_authenticated?_should_return_false_for_a_user_with_nil_digest#UserTest (1433192502.88s)
NameError:         NameError: undefined local variable or method `remember_digest' for #<User:0x0000000788d0b8>
            app/models/user.rb:38:in `authenticated?'
            test/models/user_test.rb:70:in `block in <class:UserTest>'
        app/models/user.rb:38:in `authenticated?'
        test/models/user_test.rb:70:in `block in <class:UserTest>'



ERROR["test_login_with_valid_information_followed_by_logout", UsersLoginTest, 2015-06-01 21:01:43 +0000]
 test_login_with_valid_information_followed_by_logout#UsersLoginTest (1433192503.06s)
NoMethodError:         NoMethodError: undefined method `remember_digest=' for #<User:0x00000007ba19e8>
            app/models/user.rb:28:in `remember'
            app/helpers/sessions_helper.rb:9:in `remember'
            app/controllers/sessions_controller.rb:9:in `create'
            test/integration/users_login_test.rb:22:in `block in <class:UsersLoginTest>'
        app/models/user.rb:28:in `remember'
        app/helpers/sessions_helper.rb:9:in `remember'
        app/controllers/sessions_controller.rb:9:in `create'
        test/integration/users_login_test.rb:22:in `block in <class:UsersLoginTest>'

  22/22: [===================================================================================================================================================] 100% Time: 00:00:01, Time: 00:00:01

Finished in 1.38245s
22 tests, 42 assertions, 0 failures, 2 errors, 0 skips

I am getting this error when I create my articles:

error: NameError in ArticlesController#create undefined local variable or method `article_params' for # Did you mean? article_path

image of error : enter image description here

my code :

class ArticlesController < ApplicationController
  def new
    @article = Article.new
  end

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

    private

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

    **ARTICLE CONTROLLER**                  //controller
class ArticlesController < ApplicationController
	def index
	@article=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(@article)
	end
	def destroy
	article=Article.find(params[:id])
    article.destroy
    redirect_to articles_path
	end
	def edit
	 @article = Article.find(params[:id])	
	end
	def update
	@article = Article.find(params[:id])
    @article.update(article_params)
    flash.notice = "Article '#{@article.title}' Updated!"
    redirect_to article_path(@article)
	end
	def article_params
    params.require(:article).permit(:title, :body)
    end
end

**SHOW.HTML.ERB**            /view file

<h1><%=@article.title%></h1>
<p><%=@article.body%></p>
<br><hr>

<%= link_to "edit", edit_article_path(@article) %>|
<%= link_to "delete",article_path(@article), method: :delete,data: {confirm: "Really delete the article?"} %>|
<%= link_to "<< Back to Articles List", articles_path %>
<h3>Comments</h3>
<%= render partial: 'articles/comment', collection: @article.comments %>
<%= render partial: 'comments/form' %>

**_FORM.HTML.ERB**             //_form view
<h3>Post a Comment</h3>

<%= form_for [ @article, @comment ] do |f| %>
  <p>
    <%= f.label :author_name %><br/>
    <%= f.text_field :author_name %>
  </p>
  <p>
    <%= f.label :body %><br/>
    <%= f.text_area :body %>
  </p>
  <p>
    <%= f.submit 'Submit' %>
  </p>
<% end %>
   rake routes:
 Prefix Verb   URI Pattern                  Controller#Action
articles GET    /articles(.:format)          articles#index
         POST   /articles(.:format)          articles#create
 new_article GET    /articles/new(.:format)      articles#new
edit_article GET    /articles/:id/edit(.:format) articles#edit
 article GET    /articles/:id(.:format)      articles#show
         PATCH  /articles/:id(.:format)      articles#update
         PUT    /articles/:id(.:format)      articles#update
         DELETE /articles/:id(.:format)      articles#destroy
    root GET    /                            articles#index
comments GET    /comments(.:format)          comments#index
         POST   /comments(.:format)          comments#create
 new_comment GET    /comments/new(.:format)      comments#new
edit_comment GET    /comments/:id/edit(.:format) comments#edit
 comment GET    /comments/:id(.:format)      comments#show
         PATCH  /comments/:id(.:format)      comments#update
         PUT    /comments/:id(.:format)      comments#update
         DELETE /comments/:id(.:format)      comments#destroy

i get no articles_comments_path! NoMethodError in Articles#show Showing /home/manoj/ror/blogger/app/views/comments/_form.html.erb where line #3 raised:

undefined method article_comments_path' for #<#<Class:0x00000005be3d40>:0x000000054cacc0> app/views/comments/_form.html.erb:3:in_app_views_comments__form_html_erb__3077497298558231225_47236640' app/views/articles/show.html.erb:11:in `_app_views_articles_show_html_erb__4529829459036724249_48053660'

Similar Question 4 (1 solutions) : Rails Undefined Method Path for New

Similar Question 6 (1 solutions) : undefined method `new_password_path' with activeadmin

Similar Question 9 (1 solutions) : undefined method `wikis_path'

cc