I have the following error in rails when generating a form:
No route matches {: action = > "elec_config",: controller = > "atoms"} missing required keys: [: query_val]
I have a model called Atom with 3 fields in the database and it adds an attribute in its class in the following way:
class Atom < ApplicationRecord
def initialize(*args)
@query_val = args[0]
end
end
Create the following route
get "/atoms/:query_val/elec_config", to: "atoms#elec_config", as: "elec_config"
for the elec_config method in which I do the following:
def elec_config
@atom = Atom.where("id = :id or atom_name = :atom_name or symbol = :symbol", { id: params[:query_val], atom_name: params[:query_val], symbol: params[:query_val]})
render plain: @atom.inspect ##solo para saber que este respondiendo bien
end
and when I generate the form to make the query it gives me the error already mentioned.
This is the form
<%= form_for :atom, elec_config_path do |f| %>
<%= f.label :query_val %>
<%= f.text_field :query_val %>
<% end %>
I would really appreciate your help. Thanks:)
Something else: how can I access the "id" field that returns this @num = Atom.where("id = :id or atom_name = :atom_name or symbol = :symbol", { id: params[:query_val], atom_name: params[:query_val], symbol: params[:query_val]})
and convert it to fixnum?