-1

I am trying to implement search functionality based on parameters by passing into rails model self method. While checking passed parameter conditionally on query I am getting no implicit conversion of Symbol into Integer.

my article.rb file like the following

 class Article < ApplicationRecord

  has_many :article_categories
  has_many :categories, through: :article_categories
  validates :title, presence: true, length: { minimum: 6, maximum: 100 }
  validates :description, presence: true, length: { minimum: 10, maximum: 300 }

  def self.search_artcat(params)
     @articles = Article.where(title: params[:article][:title]) if params[:article][:title].present?
  end 

end

I am accessing title and description from article parameter.

Screenshot enter image description here

Can anyone guide me to resolve this error in my query ?

1
  • Look at the incoming parameters in the terminal or log. params[:acticle] is most likely a string and not a nested instance of ActionController::Parameters. Also even if you fix that you'll still get a NoMethodError if params[:acticle] is nil. Use #dig to safely traverse the params (params.dig(:article, :title)), the nil object pattern (search_params = params.fetch(:article, {})) . Commented Nov 27, 2024 at 12:34

1 Answer 1

-1

Try to do this params[:article, :title]

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your response. I tried this. But still erroring out with same message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.