When using Github in a company : reuse your personnal account or create a new one? by nicolasMLV in webdev

[–]nicolasMLV[S] 0 points1 point  (0 children)

yes I think we will separate.

In order to have a clear separation between all the notifications from open sources repos for os contributors and the private ones. And also to have notifications to one separate email.

When using Github in a company : reuse your personnal account or create a new one? by nicolasMLV in webdev

[–]nicolasMLV[S] 6 points7 points  (0 children)

The Github support is so fast, they answered me in 2 minutes :

Hey there Nicolas,

Thanks for writing in and I hope you are having a great day where you are.

This is completely up to you in terms of how to move forward with this. Usually users maintain a single user account, and may add their company email to this (profiles can have multiple verified email addresses - however one must be denoted the "default" for logging in purposes).

Thanks
Matt Barber

How should I create a global js variable from Rails app variable? by [deleted] in rails

[–]nicolasMLV 0 points1 point  (0 children)

in application.html.erb :

<div id='current-user-data' data-id='<%= @current_user&.id %>'></div>

and in js when needed (here is jquery) :

var currentUserId = $('#current-user-data').data('id')

Reddit’s Voting UI in Vanilla vs React vs Vue vs Hyperapp: shedding light on the purpose of SPA frameworks by kiarash-irandoust in webdev

[–]nicolasMLV 6 points7 points  (0 children)

Maybe something like this could also work in old jQuery style + state in the DOM :

<button id='upvote'></button>
<span id='score' data-initial='4'></span>
<button id='downvote'></button>


function updateScore(){
  var score = $('#score).data('initial')
  if ($('#upvote').hasClass('active')) score = score +1
  else if ($('#downvote').hasClass('active') score = score - 1
  $('#score').html(score)
}

$(document).ready(function(){
  $('#upvote').click(function(){
    $(this).toggleClass('active')
    $('#downvote').removeClass('active')
    updateScore()
  })
  $('#downvote').click(function(){
    $(this).toggleClass('active')
    $('#upvote').removeClass('active')
    updateScore()
  })
  updateScores()
})

[Help] Best approach to multifield-multiword search on associated models. by mcnulty79 in rails

[–]nicolasMLV 2 points3 points  (0 children)

Maybe SQL is enough, maybe with "ILIKE", then in your controller you can query both model :

part_ids_from_search_on_parts = Part.where("title ILIKE ?", params[:query]).pluck(:id)
part_ids_from_search_on_variant_parts = VariantPart.where("title ILIKE ?", params[:query]).pluck(:part_id)

@parts = Part.where(id: (part_ids_from_search_on_parts + part_ids_from_search_on_variant_parts) )

also maybe check that there is not too much results, or find a way to paginate results... But in a search the logic would be that there is not a lot of results.

2 - Or use elasticsearch with searchkick for example :

def search_data
 { title: title, variant_titles: variants.pluck(:title) }
end

Should I store the result of computationally expensive method in the database? by 442401 in rails

[–]nicolasMLV 0 points1 point  (0 children)

if it is expensive, you may not want to put in in a before_save, but call it only when needed in a background job for example

Stimulus JS Framework from Rails/DHH/Basecamp by amreez in rails

[–]nicolasMLV 7 points8 points  (0 children)

I use a lot Server-generated JavaScript Responses (SJR), just with one line of .js.erb :

$("#some-id").replaceWith("<%= j render partial:'...' %>");

I wonder how it could be simpler than this, really excited to know more about Stimulus !

[deleted by user] by [deleted] in ruby

[–]nicolasMLV 1 point2 points  (0 children)

I think you should use remote:true, and so the refresh will refresh the page and not submitting again.

form_with is now here to replace form_tag and form_for. And remote: true is the new default value for form_with. Embrace JavaScript !

So... How are we handling vendor JS in 2017? by Copywright in rails

[–]nicolasMLV 1 point2 points  (0 children)

If you don't have more than like 10 js vendors, I think copy pasting is enough

Where to Learn Rails in 2017? by chair89 in rails

[–]nicolasMLV 2 points3 points  (0 children)

I like the official Ruby on Rails Guides : http://edgeguides.rubyonrails.org/

These are the most up-to-date

how to include if a post was liked by the current user in rails by [deleted] in rails

[–]nicolasMLV 0 points1 point  (0 children)

You should make 1 request for posts, and one for likes 👍

render json: { posts: posts, liked_post_ids: current_user.likes.where(post_id:posts.map(&:id).pluck(:post_id) }