title: Rails - routing to a parent show page with a child_id
body: <p>I would like to route to the parent (journal) show page after deleting the child (habit) using the child_id.</p>
  
  <p>In my app, a User can create journals, which then have multiple habits. I would like to be able to delete (and edit) a habit and then return to the journal show page, which displays all of the habits.</p>
  
  <p>Getting the following and similar errors: </p>
  
  <blockquote>
    <p>ActiveRecord::RecordNotFound in HabitsController#destroy</p>
  </blockquote>
  
  <p><strong>journal.rb</strong></p>
  
  <pre><code>class Journal &lt; ApplicationRecord
      has_many :entries
      has_many :habits
  
      belongs_to :user
  end
  </code></pre>
  
  <p><strong>habit.rb</strong></p>
  
  <pre><code>class Habit &lt; ApplicationRecord
      belongs_to :journal
  
      has_many :completed_dates
  end
  </code></pre>
  
  <p><strong>show.html.erb</strong></p>
  
  <pre><code>            &lt;h3&gt;Habits&lt;/h3&gt;
              &lt;% @journal.habits.each do |habit| %&gt;
                  &lt;div iv class="habit-list"&gt;
                      &lt;div class="habit-name"&gt;&lt;%= habit.name %&gt;&lt;/div&gt;
                      &lt;div class="habit-status"&gt;
                          &lt;%= simple_form_for [@journal, @habit] do |f| %&gt;
                              &lt;%= f.input :status, label: false, :inline_label =&gt; true %&gt;
                          &lt;% end %&gt;
                      &lt;/div&gt;
                      &lt;div&gt;
                          &lt;%= link_to habit_path(habit), method: :delete do %&gt;
                          &lt;i class="fas fa-trash btn-edit"&gt;&lt;/i&gt;
                          &lt;% end %&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;% end %&gt;
  </code></pre>
  
  <p><strong>habits_controller.rb</strong></p>
  
  <pre><code>class HabitsController &lt; ApplicationController
      before_action :set_journal, only: [:new, :create, :edit, :update, :destroy]
      before_action :set_habit, only: [:show, :edit, :update, :destroy]
      def index
          @habits = Habit.all.sort_by &amp;:name
      end
  
      def new
          @habit = Habit.new
      end
  
      def show
      end
  
      def create
          @habit = @journal.habits.new(habit_params)
          if @habit.save
              redirect_to journal_path(@journal)
          else
              render :new
          end
      end
  
      def edit
      end
  
      def update
          if @journal.habits.update(habit_params)
              redirect_to journals_path(@journal)
          else
              render :edit
          end
      end
  
      def destroy
          @habit.destroy
          redirect_to journal_path(@habit, @journal)
      end
  
      private
  
      def habit_params
          params.require(:habit).permit(:name, :status, :user_id, :journal_id)
      end
  
      def set_journal
          @journal = Journal.find(params[:journal_id])
      end
  
      def set_habit
          @habit = Habit.find(params[:id])
      end
  end
  </code></pre>