Different notification partials for different models? <p><strong>notifications/index</strong> has <code>&lt;%= render partial: "notifications/notification", collection: @notifications %&gt;</code>, which contains:</p> <pre><code>&lt;%= link_to "", notifications_habit_path(notification.id), method: :delete, class: "glyphicon glyphicon-remove" %&gt; &lt;%= link_to Comment.find_by(notification.comment_id).user.name, user_path(Comment.find_by(notification.comment_id).user.id) %&gt; commented on &lt;%= link_to "your habit", habit_path(notification) %&gt; </code></pre> <p>which shows:</p> <p><img src="https://i.stack.imgur.com/zVT87.png" alt="enter image description here"></p> <p>This is problematic because it should say 3x <em>".com commented on your habit"</em> and 2x <em>".com commented on your value"</em>.</p> <p>We need to create two separate partials <strong>notifications/_habits</strong> &amp; <strong>notifications/_values</strong>.</p> <p>My confusion is how to make the code know when to direct to the habit partial or the value partial based on whether it's a habit or value.</p> <p><strong>notifications_controller</strong></p> <pre><code>def index @habits = current_user.habits @valuations = current_user.valuations #aka values @notifications = current_user.notifications @notifications.each do |notification| notification.update_attribute(:read, true) end </code></pre> <p>The notifications are based on if a user comments on one of your habits or values:</p> <p><strong>comment.rb</strong></p> <pre><code>class Comment &lt; ActiveRecord::Base after_save :create_notification has_many :notifications belongs_to :commentable, polymorphic: true belongs_to :user validates :user, presence: true private def create_notification Notification.create( user_id: self.user_id, comment_id: self.id, read: false ) end end </code></pre> <p>I followed this tutorial but it is based on using just one model: <a href="http://evanamccullough.com/2014/11/ruby-on-rails-simple-notifications-system-tutorial/" rel="nofollow noreferrer">http://evanamccullough.com/2014/11/ruby-on-rails-simple-notifications-system-tutorial/</a></p> <h2>UPDATE FOR VALADAN</h2> <pre><code>class CommentsController &lt; ApplicationController before_action :load_commentable before_action :set_comment, only: [:show, :edit, :update, :destroy, :like] before_action :logged_in_user, only: [:create, :destroy] def index @comments = @commentable.comments end def new @comment = @commentable.comments.new end def create @comment = @commentable.comments.new(comment_params) if @comment.save redirect_to @commentable, notice: "comment created." else render :new end end def edit @comment = current_user.comments.find(params[:id]) end def update @comment = current_user.comments.find(params[:id]) if @comment.update_attributes(comment_params) redirect_to @commentable, notice: "Comment was updated." else render :edit end end def destroy @comment = current_user.comments.find(params[:id]) @comment.destroy redirect_to @commentable, notice: "comment destroyed." end def like @comment = Comment.find(params[:id]) @comment_like = current_user.comment_likes.build(comment: @comment) if @comment_like.save @comment.increment!(:likes) flash[:success] = 'Thanks for liking!' else flash[:error] = 'Two many likes' end redirect_to(:back) end private def set_comment @comment = Comment.find(params[:id]) end def load_commentable resource, id = request.path.split('/')[1, 2] @commentable = resource.singularize.classify.constantize.find(id) end def comment_params params[:comment][:user_id] = current_user.id params.require(:comment).permit(:content, :commentable, :user_id, :like) end end </code></pre>