Save 36% for Black Friday! Save 36% on GoRails for Black Friday! Learn more
Charlie Kay
Joined
Activity
Good tutorial Chris!
at 10:25 I am getting bellow error from console.log
Any idea why this is happening, please?
Error invoking action "scroll@window->infinite-scroll#scroll"
TypeError: "this.paginationTarget.querySelector(...) is null"
scroll infinite_scroll_controller.js:9
invokeWithEvent binding.js:52
handleEvent binding.js:29
handleEvent event_listener.js:30
infinite_scroll_controller.js
import { Controller } from "stimulus"
export default class extends Controller {
static targets = ["entries", "pagination"]
scroll() {
let url = this.paginationTarget.querySelector("a[rel='next']").href
var body = document.body,
html = document.documentElement
var height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight)
if (window.pageYOffset >= height - window.innerHeight - 100) {
this.loadMore(url)
}
}
loadMore(url) {
Rails.ajax({
type: 'GET',
url: url,
dataType: 'json',
success: (data) => {
console.log(data)
}
})
}
}
index.html.erb
Posted in Repost / Retweet / Reblog Discussion
Thanks for the quick response Chris.
I have tried @tweet.tweets.count on the tweet show page but I'm getting an error " undefined method `tweets' for #Tweet:0x007ffcab0608d8
Did you mean? tweet
tweet= "
This is showing in the console
=> #<ActiveRecord::Relation [#<Tweet id: 1, user_id: 1, body: "First tweet", tweet_id: nil, created_at: "2018-09-06 04:14:56", updated_at: "2018-09-06 04:14:56">, #<Tweet id: 2, user_id: 2, body: "second tweet", tweet_id: nil, created_at: "2018-09-06 04:16:58", updated_at: "2018-09-06 04:16:58">, #<Tweet id: 3, user_id: 2, body: nil, tweet_id: 1, created_at: "2018-09-06 04:25:34", updated_at: "2018-09-06 04:25:34">, #<Tweet id: 4, user_id: 1, body: nil, tweet_id: 2, created_at: "2018-09-06 04:54:44", updated_at: "2018-09-06 04:54:44">, #<Tweet id: 5, user_id: 1, body: nil, tweet_id: 2, created_at: "2018-09-09 12:09:01", updated_at: "2018-09-09 12:09:01">
Apart from this, everything else work fine for me in this tutorial.
Posted in Repost / Retweet / Reblog Discussion
Any help on this please; how can I count the number of times the original tweet has been retweeted?
Here is my code in the search.json.jbuilder:
json.movies do
json.array!(@movies) do |movie|
json.name movie.title.titleize + " " + "in" + " " + movie.country
json.url movie_path(movie)
end
movie.rb
def country_name
country = self.country
ISO3166::Country[country]
end
Thanks
Posted in Global Autocomplete Search Discussion
Here is my code in the search.json.jbuilder:
json.movies do
json.array!(@movies) do |movie|
json.name movie.title.titleize + " " + "in" + " " + movie.country
json.url movie_path(movie)
end
movie.rb
def country_name
country = self.country
ISO3166::Country[country]
end
Posted in Global Autocomplete Search Discussion
Thanks
def show
@related_ads = Ad.where(currency_id: @ad.currency_id)
This works fine.
belongs_to :currency
has_many :ads
Ads Controller
def show @related_ads = Ad.where.not(currency_id: @ad.currency_id)
show#view
<% @related_ads.each do |ad| %> <%= @ad.name %> <% end %>
Thanks
Posted in Global Autocomplete Search Discussion
Hi Chris, I'm trying to get my search form back to mobile responsive.
data: { behavior: "autocomplete" } in the form triggers easy-autocomplete functionality. But the search form/layout becomes mobile unresponsive when I add "data: { behavior: "autocomplete" } " Please do you know how I can fix this in the easy-autocomplete css file?
<%= form_with url: search_path, local: true, method: :get, :class => "" do |form| %>
<div class="input-group m-b-20">
<%= form.text_field :q, placeholder: "Search and select or hit enter", data: { behavior: "autocomplete" }, class: "form-control input-lg" %>
<button type="submit" class="btn btn-lg"></button> </div>
<% end %>
Posted in Global Autocomplete Search Discussion
Hey Omar, in your gem file change rails gem to the latest: gem 'rails', '~> 5.1.1' or higher
consol: bundle update
Restart your rails application
Hope this works for you
Posted in Repost / Retweet / Reblog Discussion
Thanks Chris! Sure, would love to see the follow and following relationship added to this in future.
Posted in Advanced Search, Autocomplete and Suggestions with ElasticSearch and the Searchkick gem Discussion
Finally this works:
@posts = Post.search(query, page: params[:page], per_page: 10)
Posted in Liking Posts Discussion
Hi Chris, I implemented this liking posts and it was working fine until I added Friendly_ids to the urls.
When adding the friendly_ids , the show action in Posts controller was changed from @post = Post.find(params[:id]) to @post = Post.find_by slug: params[:id]. I have tried replacing post.id under the likes_create/destroy to post.slug but it doesn't work.
Can you please advice on how to fix this?
Posted in Advanced Search, Autocomplete and Suggestions with ElasticSearch and the Searchkick gem Discussion
How can I add 'will paginate' to the search results... in class PostsController < ApplicationController?
I currently have this;
if query = params[:post_search].presence || "*"
@posts = Post.search(query, suggest: true)
Posted in Liking Posts Discussion
Here you go Aime:
https://github.com/excid3/g...