Chris Oliver

Joined

292,970 Experience
93 Lessons Completed
295 Questions Solved

Activity

Posted in Sharing on social network

You would actually need to store the title and url in a data attribute somewhere. Maybe on the twitter and facebook links themselves and then your JS could look for those, then find the attribute, and then populate the meta tag. That's probably what I'd do.

Posted in Sharing on social network

That would definitely showcase it.

Well, one solution would be to write some JS that fires on turbolinks page change to update those meta tags. It isn't the most elegant, but it would work just fine I think. See any reasons why that might not work?

Posted in Lots of trouble using LESS in a paid theme.

Whoops, sorry for not being clear there! I think there are a couple things affecting your setup.

So any of the require lines at the top are Rails asset pipeline features. They will add the file to the page, but you won't be able to access any of the code in them from other files. This is fine with normal CSS, but with LESS and SASS, you often need to reference variables in other files. That means that you must use @import for those instead, not require. Also, when you import, it's as if the code is all in the same file, so you can access variables in one file from another. That's what is probably causing your issue. You'll first want to make sure you import the variables and mixins before the other files.

On a related not, it's often bad to require_tree . because it will just go import all the files in the current directory disregarding any of the requirements of which file loads before another. I would say you should probably delete that line and it could be the source of most of your problems.

So all that said, I'd recommend changing your setup to look like this:

/*
*= Any CSS and SCSS file within this...
*
*= require twitter/bootstrap
*/

@import "a_variables";
@import "mixins";
@import "mainnav";
@import "navbar";
@import "navbar-notifications";
@import "dashboard";
@import "footer";
@import "sticky-footer";

Another useful thing is you should be able to reference the original theme's code to see which order they import these files. That will be pretty much the same order you'll want to have them imported in your code.

Good luck! I hope this helps!

Posted in Sharing on social network

Okay, so here's why I never noticed it on GoRails. The head tag does get set once and then never gets updated. The next episode you click on gets the link to change on the page, but meta tags stay the same.

Since those links are on the page, you will be fine because that's what's going to initiate the share button and it will take all the properties you set. Anytime Facebook requests the page to get OpenGraph tags, they won't be using Turbolinks so that yield will work properly as well.

Effectively it's a bug, but at the same time it doesn't affect anything (at least for me). Does it cause any issues for you that the meta tags don't get updated?

Posted in Sharing on social network

Well crap. You just made me realize that mine are broken too with the same problem!

Posted in Import a CSV with associations?

Thanks so much for the support man! I really appreciate it. :D

Ah yes, that's right. You'll want to use that instead of params[:file] in order to pass in the UploadedFile object. That's really just like a temporary file, so as long as you pass it in, you should be fine. I think if you change this in your controller, then this should work:

    Code.import(@software, code_params[:code])

Posted in Displaying previous score in current record

That's what I'm thinking too. Not sure I'll be able to help too much other than that, but let me know if you figure it out!

Posted in Import a CSV with associations?

Sup Robert!

So the main thing here is just to make sure that your import code sets up the association between the software you select in the UI and the codes that are imported.

You will want to adjust your import code accordingly in order to do that, so here's what I'd suggest:

  1. It looks like your view should have a select for the software_id so your controller can look up the appropriate software. Looks like you've got that in there with the f.association

  2. When it hits your controller, you'll want to first lookup the software these codes should be associated with. Then you'll pass that software as an additional argument into the import code.

  def import
    @software = Software.find(params[:software_id])
    Code.import(@software, params[:file])
    redirect_to codes_path, notice: 'Codes were successfully uploaded!'
  end
  1. Your import method just needs to accept a new attribute and then reference the association when creating codes now:
  def self.import(software, file)
    CSV.foreach(file.path, headers: true) do |row|
      software.codes.create! row.to_hash
    end
  end

That should do the trick!

Posted in Devise User with separate Profile

Hey Benny,

You can redirect after sign up the a ProfilesController new action. If you want to enforce it, you can set a before_action :require_profile! that redirects users to that until they have created one. All sorta depends on how you want to the user experience to be like. Just make sure your require_profile before_action gets skipped on the new and create methods for the ProfilesController and that should do the trick!

Posted in Displaying previous score in current record

This would be if you had the previous record for last week that contained that information, yes. You'd access this from the current week's record, and then you could compare the numbers between them basically.

Posted in Displaying previous score in current record

Interesting, then you may either need to calculate it based on some information you have stored, or you may need to start storing a day for that week. Either way, you will want some want to store what week that represented which will allow you to display the correct date if that makes sense.

Posted in Displaying previous score in current record

Oh wait, I think that's it! You're actually calculating the the beginning of week from today every single time you access it. Instead of using Date.today, I think you probably want to use the column saved to your record, probably week_start. That should fix it!

Posted in Displaying previous score in current record

I was going to suggest something similar.

def last_score
  user.weekly_performance_reviews.order(week_start: :desc).last
end

This would do sorting based upon the week start (assuming that was a date) but your suggestion there would work as well since it's ordering by the IDs as long as those count up.

You might have something else going wrong then if records are getting overwritten. I'm not too sure about that. Any other info you have as to what might be going wrong?

Posted in Displaying previous score in current record

Oh I see. That makes sense.

So you probably need to be able to find the previous weekly performance review from any record right? Are you setting week_start to like the Sunday or Monday beginning of each week?

Posted in Lots of trouble using LESS in a paid theme.

When you use Less or Sass (especially when variables are involved) you won't really be able to use the require section at the top for the asset pipeline. At that point, you basically just have to use the regular @import functionality of Less/Sass to do those imports.

Can you find the file that contains the border-top-radius method? It should be defined somewhere in one of those files and then when you find the file, you'll want to put that require at the top and just make sure it's included before any of the files that would be using it. I think that should do the trick for you.

Posted in Displaying previous score in current record

Interesting. Let's see if I'm understanding this right, are you looking to compare two WeeklyPerformanceReview objects?

Posted in CoffeeScript Class + Partial remotly reloaded + Binding

Awesome! Glad that worked. :D

Also just found some notes on their recommendation of which version to use: https://github.com/turbolinks/turbolinks#should-i-use-turbolinks-5-or-turbolinks-classic

I think you'll be fine using either one. I've been meaning to upgrade GoRails' Turbolinks to 5.0 but just haven't had the time yet. I'll have to do a screencast on that.

My guess is that 5.0 is okay to use, but they still haven't released some features like the iOS and Android wrappers for it which were the main purpose for 5.0. Feel free to use it though as it should also have a progress bar and will be the version that you'd need to use in the future.

I believe the main change between 2.5 and 3.0 was the addition of the partial replacement stuff. Shouldn't cause any issues when upgrading, but just note that the partial replacement functionality is getting removed in 5.0. They realized that it adds a lot of complexity for very marginal benefit and decided to remove it to keep things simple.

The video on LiveCoding.tv was mostly just exploring the partial replacements in Turbolinks classic, but since that's getting removed, it probably won't be too helpful. It sucks that their player doesn't work! I had trouble with it too and was disappointed with the site.

Posted in CoffeeScript Class + Partial remotly reloaded + Binding

Hey Thomas,

This is a good question. The basic trouble (if I'm understanding correctly) is that when you delete the file, you're re-rendering the partial but there is no UploadImage for that new element that you rendered.

I think you're correct in that you should be doing a new UploadImage(elem) in the destroy.js. My guess is that class isn't accessible globally, causing that line of code to fail. One of the issues with the JS response from a remote call is that it often hides the errors that happen, so it's harder to debug.

If it actually is that the UploadImage class isn't globally accessible, then you should need to simply change the class UploadImage to class @UploadImage to make that globally available.

Give that a shot and see if that works for you!

Also this is an okay solution for debugging that JS that you return: https://www.alfajango.com/blog/rails-js-erb-remote-response-not-executing/ You basically inspect the response in Chrome, run the JS manually in the console, and fix the errors. Not ideal, but hey, it works.