Where to implement a Linked List Stack in Rails app
<p>I am trying to implement a Linked List Stack in my Rails app which is a basic to-do list.  But I am not sure where I would place the code for the Linked List within the current Rails App structure. Can someone offer any guidance?  Would this go within the Model or the Controller?</p>

<p><strong>Screenshot of Basic to do list app</strong>
<a href="https://i.stack.imgur.com/SEZSL.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SEZSL.jpg" alt="Todolist"></a></p>

<p><strong>Tasks Controller:</strong></p>

<pre><code>class TasksController &lt; ApplicationController

 def create
   @task = current_user.tasks.build(task_params)

   if @task.save
     flash[:notice] = "Task created successfully"
   else
     flash[:error] = "Error creating task"
   end

   redirect_to current_user
 end

 def destroy
  @task = current_user.tasks.find(params[:id])

  if @task.destroy
    flash[:notice] = "Task completed successfully"
  else
    flash[:error] = "Error completing task"
  end

  redirect_to current_user
end

private

def task_params
  params.require(:task).permit(:name)
end
</code></pre>

<p><strong>Show.html.erb file for the tasks created</strong></p>

<pre><code> &lt;h1&gt;Hello, &lt;%= current_user.email %&gt;&lt;/h1&gt;

 &lt;h2&gt;Create New Task&lt;/h2&gt;
 &lt;%= form_for [current_user, @task] do |f| %&gt;
   &lt;%= f.label :name %&gt;
   &lt;%= f.text_field :name %&gt;
   &lt;%= f.submit "Create", class: 'btn btn-primary' %&gt;
 &lt;% end %&gt;
 &lt;h2&gt;Current Tasks&lt;/h2&gt;
 &lt;% current_user.tasks.each do | task| %&gt;
   &lt;p&gt;
     &lt;%= task.name %&gt;
     &lt;%=link_to [current_user, task], method: :delete do %&gt;
       &lt;span class="glyphicon glyphicon-ok"&gt;&lt;/span&gt;
     &lt;% end %&gt;
   &lt;/p&gt;
 &lt;% end %&gt;
</code></pre>

<p><strong>Task.rb(Model)</strong></p>

<pre><code>class Task &lt; ActiveRecord::Base
  belongs_to :user
end
</code></pre>

<p><strong>User.rb(Model)</strong></p>

<pre><code>class User &lt; ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  has_many :tasks
  devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable
end
</code></pre>

<p><strong>The Linkedlist Stack I would like to implement in the Rails App</strong></p>

<pre><code>module LinkedList
  class Node
    attr_accessor :value, :next_node

    def initialize(value, next_node)
      @value = value
      @next_node = next_node
      end
    end

    class Stack
      def initialize
        @first = nil
      end

      def push(value)
        @first = Node.new(value, @first)
      end

      def pop
        flash[:notice] = "Task completed successfully" if is_empty?
        value = @first.value
        @first = @first.next_node
        value
      end

      def is_empty?
        @first.nil?
      end
    end

  end
</code></pre>