Jaroslav Horák

Joined

49,330 Experience
490 Lessons Completed
0 Questions Solved

Activity

Nice cat =)

Hi Chris,
I am for sure for more episodes about rails testing 👍

Hi, I am solving very similar problem. And I think I crack it =)
For your product model you need add to search_data this

# product.rb
def search_data
  {
    option_value_id: option_values.map(&:id),
    option_type_option_value_id: option_values.map{ |option_value| option_value.option_type.id.to_s + ";" + option_value.id.to_s }
  }
end

option_type_option_value_id its a little hacky way that will help us to aggregate.
We take option_type id (like 5) and combine it with option_value id (like 10) and delimiter ; so we get something like this '5;10'
Elasticsearch will aggregate that string.

In your controller where you want to display catalog add to method

option_value_ids = array_of_option_value_ids_from_params

search_params = {}
search_params = search_params.merge(option_value_id: {all: option_value_ids}) if option_value_ids.present?

# Here we aggregate option_type_option_value_id and search with sended option values, I have pagination too
@products = Product.search "*", aggs: { option_type_option_value_id: {} }, where: search_params, page: params[:page], per_page: 25

# Here we are creating an object with option_type_id, option_value_id and count, we use this in our view
@aggs_products = @products.aggs["option_type_option_value_id"]["buckets"].map { |bucket| { option_type_id: bucket["key"].split(';')[0].to_i, option_value_id: bucket["key"].split(';')[1].to_i, count: bucket["doc_count"] } }

Now last piece the view.
Here we iterate all option types and control if we have it in our @aggs_products hash
If is there we then iterate over option type option values to test if the value is in our @aggs_products hash
If value is there we print title and count for this option (you could make it as link_to a send it as parameter to our method from above)

<% OptionType.all.each do |option_type| %>
<% if @aggs_products.any? { |h| h[:option_type_id] == option_type.id } %>
  <div class="option-type">
    <h3 class="option-type__title"><%= option_type.title %></h3>
    <ul>
      <% option_type.option_values.each do |option_value| %>
      <% if @aggs_products.any? { |h| h[:option_value_id] == option_value.id } %>
      <li>
        <%= option_value.title %> <span class="option-type__option-count">(<%= @aggs_products.detect {|c| c[:option_value_id] == option_value.id }[:count] %>)</span>
      </li>
      <% end %>
      <% end %>
    </ul>
  </div>
<% end %>
<% end %>

Hi, sadly no. I have to use a gem https://github.com/comfy/active_link_to

Hi Chris,
if I post Tweet with publish_at at 8am and reschedule it to 9am wouldn't have the first job Tweet instance with 8am?
Shouldn't I send to job only an id and find actual Tweet inside the job with latest publish_at to check?

Posted in Rails for Beginners Part 31: Tweet Partial Discussion

Hi Chris,
in video at 4:00 in tweet model. You use self.publish_at in after_initialize but only tweet_id? in published?
Why is one with self and other is not with self?

Twitter is lame =(
"Your application has been reviewed. Thank you for your interest. Unfortunately, we’re unable to to approve your application."

It's there an easy way to mark current page in navigation?

You can add 'defer' attribute on the script tag.

Hi,
I have two models User and Event.
User should belong to one group and User could attend Event based on selected group.
Event could be open for one or many groups.

My first solution was to create a Group model with has_one User and has_and_belongs_to_many for Event.
But client would not change those groups.
So is there a better way to do it without extra model and DB?

I think about something with enums but don't know how to do it with multiple groups on Event.
Or maybe there is some other solution?
Any tips? =)

Posted in Caching with Etags Discussion

Can I use this with associations in views?
I have post with author and use fresh_when on post. If I change author will it render on post view old author or new one?

Posted in How do I use Devise in normal AND API mode

Hi guys,
I want to use Devise for creating users with mobile app via REST API but I also want use it in classic fashion.
So in API I want to return JSON and appropriate HTTP codes. Also I want to issue JWT token for authentication for mobile app.
On web I want normal devise functionality.
How I should structure controllers, router and other stuff? I cant find any good resources about this.
Thank you guys.

Hi, It is a good idea to send a bunch of SMS messages after create action?
It will be better to put it in background job wouldn't?
Like with batch emails.

This is gold! Great video.
I have two questions.
Is there a way, for better SEO, to move filter params to URL?
Instead of /televisions?brand=Brick to /televisions/brand/brick ?
And second question, how to handle multiple values for attribute?
For example, if I have a color attribute for a television and the tv comes in three colors options 'Black', 'White' and 'Silver'.
Should I make three different televisions or save it as array? Or make another table or use something like hstore?
What is the best approach and how to use this filter with it?

Posted in Interface Segregation Principle Discussion

I like how this serie changing my point of view. 

Posted in Vue.js Components in Rails Views Discussion

Nice video. What about Vue state managment in Rails. When one Vue component mess with state of another Vue component?

Posted in Vue.js Trello Clone in Rails - Part 7 Discussion

Great course! I want to see something about routing with Vue. In original Trello application when you click on card the url change.
Would be awesome if you cover the Rails 5.2 features, mainly Active Storage and https://github.com/stimulus...

Posted in Vue.js Trello Clone in Rails - Part 5 Discussion

I will try flexbox instead. It is 2018 =)
Maybe something like this https://codepen.io/jaahoo/p...

Posted in How do I do multiparameter filter

Hi,
I have some sort of e-shop. I have Category model and Product model. Product has some parameters like color, material, price etc.
My question is what approach to use to filter by these parameters and categories.
Best way to include url too to be SEO friendly. Example:
www.example.com/category/subcategory/color/material?priceFrom=100&priceTo=1000
Is there some gem? Or what do you use?

Posted in Manage Assets With Rails Assets Discussion

Hi I am trying Rails Assets but I approach to a problem. I included Bourbon but when I tried use any mixin Rails told me that mixin is undefined. What to do?