Dan Donche

Joined

780 Experience
5 Lessons Completed
0 Questions Solved

Activity

Posted in Push changes to Node packages to Heroku

Figured out the problem. I feel stupid now. I had accidentally removed
<%= javascript_pack_tag 'application' %>
from my application.html.erb file.

Posted in Push changes to Node packages to Heroku

Okay, full disclosure, I upgraded to Rails 6 without fully understanding the consequences of using Actiontext and Webpacker. It's all new to me. So in my folly, I changed some of the Trix css directly in the Node packages directory instead of making them in the actiontext.css file that lives in the asset pipeline.

I encountered some issues after I started putting my css into the actiontext.css file, so (probably like an idiot) I just pulled all the css from the Trix folder (leaving it empty) and put it into the actiontext one. It mostly worked okay for a week or so.

I don't know what happened to my app, but now I cannot see the Trix editor when I go to edit any model that uses actiontext.

I am wondering how I can reset to original Trix files and push the node packages to Heroku. I feel as though these were only pushed the first time I installed Yarn and Node on Heroku. I'm not fully understanding this process. Any help would be appreciated.

I remembered posting about this. I found this article on how to make the Trix toolbar sticky, in case anyone is interested.
https://tosbourn.com/sticky-trix-toolbar/

I managed to temporarily remove the file upload icon with css.

trix-toolbar .trix-button--icon-attach {
  display: none;
}

Posted in How to use ActionText in Rails 6 Discussion

If you have this issue, set this in node_modules/trix/dist/trix.css:

 .trix-button-row { 
   display: flex; 
   flex-wrap: wrap; 
   justify-content: space-between; 
 } 

Posted in How to use ActionText in Rails 6 Discussion

Anybody know how to make the trix editor look fine on mobile?

Posted in User Onboarding Progress Bar Discussion

I have a weird issue going on with this. I previously implemented the activity feed from another video. Now whenever a user achieves 100 percent progress in this onboarding profile, it updates the onboarding_completed_at column as expected. Only thing is rails automatically inserts a new Activity with empty values into the database, which throws errors on the user dashboard.

 (0.0ms)  begin transaction
  SQL (1.7ms)  UPDATE "users" SET "onboarding_completed_at" = ?, "updated_at" = ? WHERE "users"."id" = ?  [["onboarding_completed_at", "2019-07-23 05:54:51.413467"], ["updated_at", "2019-07-23 05:54:51.750723"], ["id", 3]]
  SQL (0.2ms)  INSERT INTO "activities" ("user_id", "created_at", "updated_at") VALUES (?, ?, ?)  [["user_id", 3], ["created_at", "2019-07-23 05:54:51.754118"], ["updated_at", "2019-07-23 05:54:51.754118"]]
   (13.4ms)  commit transaction

Here is the error. Specifically it is talking about hte lookup_context line:

undefined method empty?' for nil:NilClass

<% if @feed_items.any? %>
    <% @feed_items.each do |item| %>
      <% if lookup_context.template_exists?(item.eventable_type, "dashboards/types", true) %>
        <div class="row p-2">
          <div class="col-3 col-md-2">
            <% if item.user.image? %>

My module here is exactly like the one in the video, I have only added other steps. (Also, the :has_followed? method appears in my user model already, and it works. Nothing in my users controller calls for an Activity to be created. In fact, this only occurs in specific controllers where something like a comment or a new post is created.

Why might this be happening?

module UserOnboarding
    extend ActiveSupport::Concern

    def should_see_onboarding?
        !onboarding_completed_at? || onboarding_completed_at > 1.day.ago
    end

    def onboarding_percent
        return 100 if onboarding_completed_at?

        steps = [:image?, :bio?, :has_favorite?, :has_followed?, :has_topic?, :has_comment?, :has_review?]
        complete = steps.select{ |step| send(step) }
        percent = complete.length / steps.length.to_f * 100
        update(onboarding_completed_at: Time.current) if percent == 100
        percent
    end

    def has_favorite?
        favorites.any?
    end

    def has_topic?
        topics.any?
    end

    def has_comment?
        comments.any?
    end

    def has_review?
        reviews.any?
    end
end

Posted in Activity Feed From Scratch Discussion

So I managed to fix this by changing it from :destroy to :delete_all.
has_many :activities, as: :eventable, dependent: :delete_all

Posted in Activity Feed From Scratch Discussion

Is this something where I would need to use a cascade? I do not understand the differences.
*Update, it seems like the immediate events are not being deleted along with the listing as well.

Posted in Activity Feed From Scratch Discussion

I have my events set up. Some of the models I have are listings and reviews. Reviews belong to listings. If someone leaves a review for a listing, the event saves both the review id (as eventable_id) and the listing id (as parent_id). So I can link to both in the view.

My problem is that if I deleted the listing, the review event remains, and rails throws an error (can't find listing with id 25, for example).

Here is my listing model:

class Listing < ApplicationRecord
  belongs_to :user
  has_many :reviews, dependent: :destroy
  has_many :activities, as: :eventable, dependent: :destroy

My reviews model also has
has_many :activities, as: :eventable, dependent: :destroy

The issue I'm having is that the listing gets deleted, and the reviews and events associated with that listing get deleted. But the events associated with the reviews do not get deleted. Did I do something wrong in the association?

Posted in SEEKING FREELANCER, Colorado Springs, remote: true

Note: I would also be willing to transition from Carrierwave to Active Storage if that would make everything easier.

Posted in SEEKING FREELANCER, Colorado Springs, remote: true

I have a Rails app I built with 5.2. It's intended to be similar to Soundcloud in some ways, Spotify in others. I am using Carrierwave to upload audio files to Amazon S3. One of the things I would like to hire a more skilled developer for is 1) writing id3 tags to these audio files when they get uploaded and 2) figuring out why the track information doesn't display via Bluetooth. I would also like to accept more audio types than mp3, and perhaps convert them to mp3 on upload.

Note that this will lead to more work in the future as tasks become available that I don't have time to do.

Posted in Activity Feed From Scratch Discussion

Great video, man. I had originally figure out how to do this on my own, and was like, "that's me!" when you mentioned how not to do it. Thanks for showing an alternative to "if activity type is this, show this". I was able to refactor quite a bit of code.

Hey Chidozie, that is very helpful. I'm using the trix gem, though, I don't think I can edit the css. I may have to do it manually. 

Posted in Liking Posts Discussion

I have one more question about this. I have this working on the individual show page, but how can I properly render the button for an index of the posts? 

This is my partial at tracks/favorites 
<% if user_signed_in? && current_user.favorited?(@track) %>
<%= link_to image_tag('icons/heart_full.svg', width: 20), track_unfavorite_path(@track), method: :post, remote: true %>
<% else %>
<%= link_to image_tag('icons/heart_empty.svg', width: 20), track_favorite_path(@track), method: :post, remote: true %>
<% end %>

My js files are here 
$("#favorites").html("<%= escape_javascript(render('tracks/favorites')) %>");

The problem is when I try to render the partial onto an index. I am looping through all favorited items here as "item".  Everything works fine until I include the partial. 
<div id="favorites">
<%= render 'tracks/favorites', :track => item %>
</div>

When I use this, I get an error.  
undefined method `favorites' for nil:NilClass

It is telling me the problem is with this method. 

  def favorited?(track)

track.favorites.where(user_id: id).any?

end
I am trying to figure out how to add a scroll bar to the textarea in Trix. Any suggestions? I'm using the gem. If there is a lot of content in the textarea, you have to scroll all the way back up just to change a word to bold or italic, etc., and then scroll all the way back to where you were, if you can find it. You can try it out yourself right here. 

Posted in Liking Posts Discussion

Disregard. I wrote the code correctly here, but in my user.rb file I had it written as

 
 def favorited?(track)
    track.favorites.where(user_id: :id).any?
  end 


Posted in Liking Posts Discussion

Another great episode. I'm setting this up now, users can favorite audio tracks. My models are User, Track, and Favorite. I'm stuck on the part where my partial renders "unfavorite" or "favorite" depending on whether the association exists. 

<% if user_signed_in? && current_user.favorited?(@track) %>
  <%= link_to "Unavorite", track_unfavorite_path(@track), method: :post %>
<% else %>
  <%= link_to "Favorite", track_favorite_path(@track), method: :post %>
<% end %>

The problem is, if you click to favorite the track in the view, the new favorite gets created in the database, but the view still says "favorite" instead of "unfavorite." 

 => #<Favorite id: 2, user_id: 3, track_id: 6, created_at: "2018-06-21 15:47:33", updated_at: "2018-06-21 15:47:33">

Something seems to be wrong with the method in my user model. It's not recognizing that the record exists. 

  def favorited?(track)
    track.favorites.where(user_id: id).any?
  end

I have also tried

favorites.include?(track)

but that doesn't work either. No matter which version I try, my view doesn't recognize that there's a favorite already. 
You would need to add a username column to your users table in the database and then everything else should be the same as in the video. 

Posted in Repost / Retweet / Reblog Discussion

This was just what I needed, man. I tried to build out this feature myself and I ended up making it way more complicated than it should have been. I also now understand a few more things about Rails, so thanks for this. 
logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.