# Anchor
click_link 'Save'
# Button
click_button 'awesome'
# Both above| require 'nokogiri' | |
| require 'open-uri' | |
| # Get a Nokogiri::HTML:Document for the page we're interested in... | |
| doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove')) | |
| # Do funky things with it using Nokogiri::XML::Node methods... | |
| #### |
| require "bundler/inline" | |
| gemfile do | |
| source "https://rubygems.org" | |
| gem "activerecord", require: "active_record" | |
| gem "activejob", require: "active_job" | |
| gem "sqlite3" | |
| gem "searchkick", git: "https://github.com/ankane/searchkick.git" | |
| end |
The normal controller/view flow is to display a view template corresponding to the current controller action, but sometimes we want to change that. We use render in a controller when we want to respond within the current request, and redirect_to when we want to spawn a new request.
The render method is very overloaded in Rails. Most developers encounter it within the view template, using render :partial => 'form' or render @post.comments, but here we'll focus on usage within the controller.
| stats = Sidekiq::Stats.new | |
| stats.queues | |
| stats.enqueued | |
| stats.processed | |
| stats.failed |
| #!/usr/bin/env ruby | |
| # If you're not using rbenv in this script's dir, you may wanna run | |
| # these as `sudo gem install ruby-trello`, etc. | |
| ['ruby-trello', 'dotenv'].each do |gem_name| | |
| begin | |
| gem gem_name | |
| rescue LoadError | |
| puts "Running `gem install #{gem_name}`..." | |
| puts "If this takes too long, you may want to run it manually, as `sudo` if needed." |
By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:
/people/6
But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.
- Website: https://stimulusjs.org/
- GitHub repo: https://github.com/stimulusjs/stimulus
- Handbook: https://stimulusjs.org/handbook/introduction
- Discourse: https://discourse.stimulusjs.org/
initialize: once, when the controller is first instantiatedconnect: anytime the controller is connected to the DOM
In attempting to install Ruby with rbenv, I ran into the following build failures:
BUILD FAILED (macOS 11.2.3 using ruby-build 20210423)
Inspect or clean up the working tree at /var/folders/58/16lnyx815c183j6wzcbl_thc0000gn/T/ruby-build.20210426232453.81982.XfAg0C
Results logged to /var/folders/58/16lnyx815c183j6wzcbl_thc0000gn/T/ruby-build.20210426232453.81982.log
Last 10 log lines:
^
| HTTP status code symbols for Rails | |
| Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings. | |
| Status Code Symbol | |
| 1xx Informational | |
| 100 :continue | |
| 101 :switching_protocols | |
| 102 :processing |