azback5
Joined 10/27/2020
azback5 said about 4 years ago on Nested Comments from Scratch :
I've been trying to add a feature here where we can also EDIT our comments. 

In comments controller I have added:

  def edit
      @comment = @commentable.comments.find(params[:id])
    end

    def update
       @comment.update!(comment_params)
       redirect_back(fallback_location: root_url)
       render "edit"
    end

__________________________________

And in our views _comment.html.erb partial i added in the div 'links'

<%= link_to 'Edit', [:edit, comment.commentable, comment] %>

__________________________________________________________

I am confused what to populate the edit.html.erb file with. Do you have any suggestions?

Thanks


azback5 said about 4 years ago on Nested Comments from Scratch :
thanks for your help! 

I'm a rookie with javascript and I'm eager to learn it, so I feel obliged to ask...

How would you go about writing the JS to render the form partial and display a modal? 

(Great tutorial by the way, I've been teaching myself and this helped me a great deal)



azback5 said about 4 years ago on Nested Comments from Scratch :
Thanks, I'll check this out.

azback5 said about 4 years ago on User Notifications :
Hey  ... I'm having some trouble implementing the notifications feature into my rails app.

The notifications counter updates perfectly in my app layout view, but when I try to click on the notifications url I keep receiving a 500  NameError and it's parsing through and fussing with a link to root_path in my app/layout which doesn't make sense, to me as I know that works fine.


in my comment.rb model

class Comment < ApplicationRecord


  after_commit :create_notifications, on: :create

  belongs_to :commentable, polymorphic: true
  has_many :comments, as: :commentable
  belongs_to :user, optional: true

  validates :body, presence: true

  def deleted?
    user.nil?
  end

  private

  def create_notifications
   Notification.create do |notification|
     notification.notify_type = 'commentable'
     notification.actor = self.user
     notification.user = self.commentable.user
     notification.target = self
     notification.second_target = self.commentable
   end
 end

end


in my views/notifications/_commentable.html.erb
<div class=''>
  <%= link_to notification.actor.email, main_app.user_path(notification.actor) %> has commented in

</div>

<div class=''>
  <%= notification.target.body %>
</div>


Do you have any ideas as to what might be creating the fuss?

Thanks a lot!

Aaron