Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
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.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

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
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!