module QuotesHelper
# overrriding this
# => wrong number of arguments (given 3, expected 2)
def pagy_url_for(pagy, page)
page
end
end
# psuedo-code
turbo_frame_tag "items", src: items_path do
<div id="modal">
<div id="items to paginate>
<%== pagy_nav(pagy) %>
</div>
end
# controller
def index
@q = Quote.ransack(params[:q])
@pagy, @quotes = pagy(@q.result(distinct: true))
end
def search
index
Grafted from Andy Jeffries' work.
We're going to walk through the two most common scenarios when first using Phlex. The first is to take an existing Rails application, realise you could do with more componentisation and extract part of a view to a Phlex View. The second is to entirely replace the view layer of an application with Phlex Views, to get rid of writing raw HTML and encourage reuse of components structure and styling (particularly when using TailwindCSS for example, which can become very verbose with classes everywhere).
Let's imagine we have a very simple Rails application that shows off a list of books. We've created a simple model called Book
and a BookController
along with the requisite index.html.erb
. For today we'll ignore the more complex aspects of authentication, and editing/deleting the models, etc and just work with that view, as the process is really the same.
# really sounds like an X-Y problem
# there are many ways to skin a cat
# what about just using a different end point for the count?
# or a mock object in lieu of pagy
# or just decouple from pagy entirely!!
def index
@pagy, @results = pagy(query)
Consider some html - this is what we want to create:
<div id="start-of-content" class="show-on-focus">
<p> Setting innerHtml on the #start-of-content element to "" would wipe this msg away </p>
</div>
(If you're reading this on Github, you can open the dev tools and see the relevant element.)
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
source ~/Downloads/Programs/fm/fm.zsh
# production.rb
# mail gun
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = { address: "smtp.mailgun.org",
port: 587,
user_name: Chamber.dig!(:smtp_email, :mail_username),
password: Chamber.dig!(:smtp_email, :mail_password),
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tekla.Structures.Geometry3d;
using Tekla.Structures.Model;
namespace RopesProject
[!] There was an error while loading `pagy.gemspec`: /home/koshy/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/bundler/gems/pagy-7c9eb10dd089/lib/pagy/frontend.rb:26: syntax error, unexpected '='
... def pagy_get_params(params) = params
... ^
/home/koshy/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/bundler/gems/pagy-7c9eb10dd089/lib/pagy/frontend.rb:97: syntax error, unexpected end-of-input, expecting end. Bundler cannot continue.
# from /home/koshy/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/bundler/gems/pagy-7c9eb10dd089/pagy.gemspec:5
# -------------------------------------------
# $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
> require 'pagy'