ruby on rails - Action View missing Template in RoR 5 when calling instance variable from controller -


trying render to-do list ajax through ruby on rails. here 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. message states "missing partial tasks/_task "

my controller declares @tasks = task.all 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 issue in situation.

any appreciated.

it's asking task partial within app/views/tasks folder.

to use or print @tasks call use in view using ruby inside views <%= ruby_code %>

by default, controllers in rails automatically render views names correspond actions, means if use <%= render @tasks %>, rails try find partial called tasks within parent folder that's printing current view.

also i've seen you're assigning twice value of @books in index method, if you're using before_action :all_tasks in index don't need "redeclare" 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 

Comments