Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
Action View missing Template in RoR 5 when calling instance variable from controller

Trying to render a to-do list with Ajax through Ruby on Rails. Here is the index.html.erb snippet:

<div class="row">
  <div class="col-md-7 col-md-offset-1" id="tasks"><%= render @tasks %></div>
</div>

The error raises when render @tasks hits. The message states "Missing partial tasks/_task "

My controller declares that @tasks = Task.all as follows

class TasksController < ApplicationController
before_action :all_tasks, only: [:index, :create]
respond_to :html, :js

def index
    @tasks = Task.all
end

def new
    @task = Task.new
end

def create
    @task = Task.create(task_params)
end

private

    def all_tasks
        @tasks = Task.all
    end

    def task_params
        params.require(:task).permit(:description, :deadline)
    end
end

Not sure what the issue is in this situation.

Any help appreciated.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

It's asking for a task partial within your app/views/tasks folder.

To use or print @tasks you just call use it in your view using Ruby inside your views like <%= ruby_code %>

By default, controllers in Rails automatically render views with names that correspond to actions, it means if you use <%= render @tasks %>, Rails will try to find for some partial called tasks within the parent folder that's printing the current view.

Also I've seen you're assigning twice the value of @books in your index method, if you're using the before_action :all_tasks in your index then you don't need to "redeclare" it again.

Try with:

# app/views/index.html.erb
<div class="row">
  <div class="col-md-7 col-md-offset-1" id="tasks">
    <%= @tasks %>
  </div>
</div>

# app/controllers/tasks_controller.rb
class TasksController < ApplicationController
  before_action :all_tasks, only: [:index, :create]
  respond_to :html, :js

  def index
  end

  def new
    @task = Task.new
  end

  def create
    @task = Task.create(task_params)
  end

  private

  def all_tasks
    @tasks = Task.all
  end

  def task_params
    params.require(:task).permit(:description, :deadline)
  end
end
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda