mercredi 25 mai 2022

Rails: no implicit conversion of Symbol into Integer

I have created a form where i have to get input from user,Here each article have unique id by which we fetch the article and from their we want to grab the value entered by user for that article I tried this but getting error. "no implicit conversion of Symbol into Integer"

this is my _form_data.html.erb code:

    <%= form_for :fetch_content, url: article_path(@article), method: :get do |f| %>
    
    <div class="form_data_id">
  <%= f.text_field :paras, placeholder:"Enter value" %>
    </div>
    
    <span id="error"></span>
    
    <div class="form_data_submit">
      <input id="submitBtn" type="submit" name="commit" value="Save" data-disable-with="Save Api options" onmouseover="myFunction1()">
    </div>
    
    
    <% end %>

articles_controller.rb

<!-- Here i tried to get the value from User in count instance variable -->
  def show
    @article = Article.find(params[:id])
    fetch_content
  end

  def fetch_content
    p '@^$#%^^#%%%^%#$#$#%@#%$&&%&%##%$#$'
    count = Article.find(params[:id][:api_options_paras])
    if (count>5 && count <1)
      @bacon = get_content(count,'all-meat')
    else
      @bacon = get_content(1,'all-meat')
    end
  end

This is my routes.rb file

# frozen_string_literal: true

Rails.application.routes.draw do
  root 'articles#index'

  get 'articles/:id/fetch_content',to: 'articles#fetch_content'

  resources :articles do
    resources :comments
  end
end

getting error :

TypeError (no implicit conversion of Symbol into Integer):

app/controllers/articles_controller.rb:18:in `[]'
app/controllers/articles_controller.rb:18:in `fetch_content'
app/controllers/articles_controller.rb:13:in `show'
Started GET "/articles/1?api_options%5Bparas%5D=2&commit=Save" for ::1 at 2022-05-25 18:02:07 +0530
Processing by ArticlesController#show as HTML
  Parameters: {"api_options"=>{"paras"=>"2"}, "commit"=>"Save", "id"=>"1"}
   (0.1ms)  SELECT sqlite_version(*)
  ↳ app/controllers/articles_controller.rb:12:in `show'
  Article Load (1.3ms)  SELECT "articles".* FROM "articles" WHERE "articles"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/articles_controller.rb:12:in `show'
"@^$#%^^#%%%^%\#$\#$#%@#%$&&%&%##%$\#$"
Completed 500 Internal Server Error in 54ms (ActiveRecord: 12.1ms | Allocations: 4648)



TypeError (no implicit conversion of Symbol into Integer):

app/controllers/articles_controller.rb:18:in `[]'
app/controllers/articles_controller.rb:18:in `fetch_content'
app/controllers/articles_controller.rb:13:in `show'

Aucun commentaire:

Enregistrer un commentaire