undefined local variable or method 'data_state' for #MaximaController: 0x667fd58

1

I apologize, but it must be to weariness, I do not see the error: (

the driver:

class MaximosController < ApplicationController
  before_action :set_maximo, only: [:show, :edit, :update, :destroy]

  # GET /maximos
  # GET /maximos.json
  def index
    ver_datos
    @maximos = Maximo.all
  end
....

UPDATE MODEL (same error)

the model:

class Maximo < ApplicationRecord
end

Private
  def ver_datos
    puts 'dentro de ver datos'
  end

the error:

Started GET "/" for 127.0.0.1 at 2017-11-02 12:45:43 -0400
Processing by MaximosController#index as HTML
Completed 500 Internal Server Error in 250ms



NameError (undefined local variable or method 'ver_datos' for #<MaximosController:0x5525328>):

app/controllers/maximos_controller.rb:7:in 'index'
Started GET "/" for 127.0.0.1 at 2017-11-02 12:46:22 -0400
Processing by MaximosController#index as HTML
  Rendering maximos/index.html.erb within layouts/application
  Maximo Load (1.0ms)  SELECT "maximos".* FROM "maximos"
  Rendered maximos/index.html.erb within layouts/application (9.0ms)
Completed 200 OK in 6686ms (Views: 6636.2ms | ActiveRecord: 3.0ms)


Started GET "/" for 127.0.0.1 at 2017-11-02 12:47:03 -0400
Processing by MaximosController#index as HTML
Completed 500 Internal Server Error in 265ms



NameError (undefined local variable or method 'ver_datos' for #<MaximosController:0x667fd58>):

app/controllers/maximos_controller.rb:7:in 'index'
    
asked by rrg1459 02.11.2017 в 17:51
source

1 answer

0

In your Maximo model, the ver_datos method is defined as the instance method, that means you should have a maximum object and then call the method, something like:

maximo = Maximo.find(params[:id])
maximo.ver_datos

Now, if the logic of ver_datos is not related to an instance, maybe what you need is a class method, for which you should define your method as def self.ver_datos instead of def ver_datos , then then from your controller you call it with:

Maximo.ver_datos

Note that Maximo starts with a capital letter, which means that the class is called, not the instance as in the previous example.

    
answered by 02.11.2017 / 18:06
source