This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in development.rb | |
config.action_controller.perform_caching = true | |
# in app/models/product.rb | |
def self.latest | |
Product.order(:updated_at).last | |
end | |
# in app/views/store/index.html.erb | |
<% cache [ 'store', Product.latest ] do %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test "product is not valid unless title is at least 10 characters long" do | |
product = Product.new( | |
title: "Book", | |
description: "yyy", | |
price: 1, | |
image_url: "fred.jpg" | |
) | |
assert product.invalid? | |
assert_equal ["Please ensure title is at least 10 characters long"], product.errors[:title] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
<<<<<<< HEAD | |
@bookmark = Bookmark.new(bookmark_params) | |
@bookmark.save | |
flash[:notice] = "Bookmark added!" | |
redirect_to root_path | |
======= | |
@bookmark = Bookmark.new(params[:create]) | |
if @bookmark.save | |
# render text: "Thanks for sending a GET request with cURL! #{request.body.read}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ ruby_bookmark_drag git:(jlh_master_url_fixer_method) git pull origin master | |
remote: Counting objects: 26, done. | |
remote: Compressing objects: 100% (22/22), done. | |
remote: Total 26 (delta 15), reused 15 (delta 4), pack-reused 0 | |
Unpacking objects: 100% (26/26), done. | |
From github.com:powelljmp/ruby_bookmark_drag | |
* branch master -> FETCH_HEAD | |
0673691..2cec1be master -> origin/master | |
Auto-merging app/views/shared/_form.html.erb | |
CONFLICT (content): Merge conflict in app/views/shared/_form.html.erb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ ruby_bookmark_drag git:(jlh_master_url_fixer_method) tail -f log/development.log | |
Started GET "/assets/z_custom.js?body=1" for 127.0.0.1 at 2015-03-22 21:01:02 +0000 | |
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2015-03-22 21:01:02 +0000 | |
Started GET "/assets/create.js?body=1" for 127.0.0.1 at 2015-03-22 21:01:02 +0000 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This is a manifest file that'll be compiled into application.css, which will include all the files | |
* listed below. | |
* | |
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, | |
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. | |
* | |
* You're free to add application-wide styles to this file and they'll appear at the bottom of the | |
* compiled file so the styles you add here take precedence over styles defined in any styles | |
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# routes | |
post 'todos/:id/pinned', to: 'todos#pinned', as: :pinned_todo | |
post 'todos/:id/unpin', to: 'todos#unpin', as: :unpin_todo | |
# controller | |
def pinned | |
flash[:notice] = 'Todo pinned for today' | |
@todo.pinned = true | |
@todo.save | |
redirect_to root_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_slug | |
the_slug = to_slug(self.title) | |
post = Post.find_by(slug: the_slug) | |
count = 2 | |
while post && post != self | |
the_slug = append_suffix(the_slug, count) | |
post = Post.find_by(slug: the_slug) | |
count += 1 | |
end | |
self.slug = the_slug.downcase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_slug(post_title) | |
the_slug = post_title.gsub(/[\W_]/, '-').squeeze.chop.downcase | |
return the_slug | |
end | |
def ensure_slug_not_duplicate | |
the_slug = make_slug(self.title) | |
post = Post.find_by(slug: the_slug) | |
counter = 2 | |
while post && post != self |
NewerOlder