サクサク読めて、アプリ限定の機能も多数!
トップへ戻る
アメリカ大統領選
www.justinweiss.com
Last week, during RailsConf 2017, Rails 5.1 shipped. If you followed the announcements, you’ve seen the big features: better integration with modern JavaScript, encrypted secrets, and system tests. And there’s my personal favorite: finally getting rid of the weird combo of form_for and form_tag, and replacing it with form_with. I can’t wait to try it. But the reason I love Rails isn’t the big new
How Rails Sessions Work What if your Rails app couldn’t tell who was visiting it? If you had no idea that the same person requested two different pages? If all the data you stored vanished as soon as you returned a response? That might be fine for a mostly static site. But most apps need to be able to store some data about a user. Maybe it’s a user id, or a preferred language, or whether they alwa
This article is also available in Korean, thanks to Soonsang Hong! Rails’ scopes make it easy to find the records you want: app/models/review.rbclass Review < ActiveRecord::Base belongs_to :restaurant scope :positive, -> { where("rating > 3.0") } end irb(main):001:0> Restaurant.first.reviews.positive.count Restaurant Load (0.4ms) SELECT `restaurants`.* FROM `restaurants` ORDER BY `restaurants`.`id
4 Simple Memoization Patterns in Ruby (And One Gem) Memoization is a technique you can use to speed up your accessor methods. It caches the results of methods that do time-consuming work, work that only needs to be done once. In Rails, you see memoization used so often that it even included a module that would memoize methods for you. Later, this was controversially removed in favor of just using
How Does Rails Handle Gems? A few weeks ago, I wrote about how RubyGems manages Ruby’s load path. But Rails doesn’t use RubyGems directly – it uses Bundler to manage its gems. If you don’t know how Bundler works, the way gems get pulled into Rails might seem a little too magical. How does adding a line to a Gemfile get code into your app? How do Bundler, Rails, and RubyGems work together to make h
Rails 5, Module#prepend, and the End of `Alias_method_chain` The Rails 4.2 announcement had some interesting news about the upcoming Rails 5: It’s probably going to require Ruby 2.2. Which will make it the first Rails version to take advantage of all the good stuff from Ruby 2. The post mentioned garbage collected symbols and keyword arguments. But to me, one of the most interesting Ruby 2 feature
When you research how to deploy your Rails app, you’ll see a lot of names: Apache, Unicorn, Puma, Phusion Passenger, Nginx, Rainbows, and many more. They all seem to fit under the “deploying Rails” category of software, but there’s a key difference between them. Some are “web servers,” and others are “app servers.” Once you understand which is which, and where each category fits in your system, de
Imagine a question that can be either “pending”, “approved”, or “flagged”. Or a phone number that’s a “home”, “office”, “mobile”, or “fax” (if it’s 1982). Some models call for this kind of data. An attribute that can have only one of a few different values. And that set of values almost never changes. It’s a situation where, if it were plain Ruby, you’d just use a symbol. You could create a PhoneN
A New Way to Understand Your Rails App's Performance Is your Rails app slow? When it takes seconds to load what should be a simple view, you have a problem worth digging into. You could have too many database calls or some slow methods. Or maybe it’s that speedup loop someone put in your code and forgot about. You can find lots of tools to help you find out what’s slowing your app down. A few week
What's the Difference Between `Irb`, `Bundle Exec Irb`, `Bundle Console`, and `Rails Console`? There are a lot of ways to launch a Ruby or Rails console: irb, bundle exec irb, bundle console, and rails console are some of the most common. They seem similar, but they each work a little bit differently. If you don’t know what those differences are, you’ll have some problems. Maybe you won’t be able
How to Debug Ruby Performance Problems in Production You know that performance is a feature. And a lot of performance problems can be found and fixed during development. But what about those slowdowns that only show up in production? Do you have to add log messages to every single line of code? That would just slow things down even more! Or do you ship tons of tiny “maybe this fixes it” commits to
How to Upgrade to Rails 4.2 Upgrading some Rails apps is as easy as bundle update rails. But what if you have one of the other kind of apps? The ones that are still on Rails 4.0, or even 3.2, because you didn’t feel like dragging them kicking and screaming into the future? Whether you’re facing a quick upgrade or a painful one, these steps will help you get your app to Rails 4.2 as smoothly as pos
3 Ways to Monkey-Patch Without Making a Mess Monkey Patching. When you first try Ruby, it’s amazing. You can add methods right to core classes! You don’t have to call Time.now.advance(days: -1), you can write 1.day.ago! It makes Ruby a joy to read and write. Until… You hit weird bugs because a patch changed Hash. You get confused about which code actually ran, so you can’t debug it when it breaks.
Better Globals With a Tiny ActiveSupport Module Generally, global variables are bad. But sometimes, a global in the right place can make your code a lot simpler. In Rails, you might set data once during a request, but use it in every layer of your app. Which user is making the request? What permissions do they have? Which database connection should be used? This information should be available thr
`Respond_to` Without All the Pain When you generate a scaffold in Rails, you’ll see the usual respond_to blocks: app/controllers/tasks_controller.rb def destroy @task.destroy respond_to do |format| format.html { redirect_to tasks_url, notice: 'Task was successfully destroyed.' } format.json { head :no_content } end end But some of your actions, like index, don’t have them! app/controllers/tasks_co
“The goal of Ruby is to make programmers happy. So why do I have to slog through 400 pages on RSpec and Capybara and Bootstrap and Sass before I can write a simple blog?” You’re on your second Rails tutorial, and you feel like flipping a table. Writing a Rails app is supposed to be easy, right? But even if you’ve seen all the pieces, you don’t know how they fit together. Everywhere you look there’
If you want to write great Rails apps, there’s a lot you’ll need to know. Sometimes, it feels impossible to keep up. But if you don’t seek out new knowledge, you’ll fall behind. You don’t have to dig for great Rails information, if it finds you. To help you write great Rails apps, I send new weekly articles to more than 6,000 Rails developers. Sign up, and you’ll learn how to speed up your apps, d
The Lesser-Known Features in Rails 4.2 The first beta of Rails 4.2 was announced last week, and it already looks amazing. I’m really excited to use ActiveJob, Web Console, Adequate Record, and Foreign Key support in my own apps. But the beauty of Rails is in the details. And if you do a little digging, you’ll find some less advertised features that will totally improve your daily work with Rails.
Search and Filter Rails Models Without Bloating Your Controller Searching, sorting, and filtering in Rails controllers can be a pain. ElasticSearch and Solr are great, high-powered solutions, but are really big dependencies for a small app. Luckily, Rails includes scopes, which can provide you with a lot of what you need for simple searching, filtering, and sorting. If you take advantage of scope
このページを最初にブックマークしてみませんか?
『Justin Weiss』の新着エントリーを見る
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く