RailsCasts Pro episodes are now free!

Learn more or hide this

Frédéric's Profile

GitHub User: elblaf

Comments by Frédéric

Avatar

Instead of booleans (or STI), you can also use a state machine (last week pro episode ;-)) to keep track of the user's status (guest, registered user, admin...), for instance as describe in this railstips blog (this example modeli{s,z}es an inactive/active/abusive user).

Avatar

Each time you create a new MIME type name (application/vnd.example.v1, application/vnd.example.v2, ...), a kitten is hurt! don't do that! that's bad!

Use MIME parameters instead: application/vnd.example; version=1, application/vnd.example; version=2, ... (version=, or level=, or v= or whatever you want, this is part of your design).

The semantic of a MIME type is that every document "flagged" with that type share the same "lineage", and that two different names are not related, even if they share a same prefix.

By incorporating a version identifier into the MIME type name, you are making the names distinct and are in the same case as if your V1 API was using text/html documents whereas your V2 now uses image/png pictures instead.

Avatar

Answer to your question is in the screencast (between 6:30-6:50) and QC documentation; simply write your own worker "binary" (weird to use that term for a script file...) that only loads what's needed.

Avatar

Joshua Cheek's screeencast is also worth seeing, and includes a neater way to use Pry as IRB replacement for the rails console:

Simply add the following lines at the end of your config/environments/development.rb file, after the YourAppName::Application.configure block:

ruby
silence_warnings do
  require 'pry'
  IRB = Pry
end

And no more need to use the longer pry -r config/environment to start the console: simply use the usual rails console/rails c command.

Avatar

Based on the source code provided with this screencast (for the <%= yield(:head) %> in the app/views/layouts/application.html.erb ), update the app/views/snippets/show.html.erb to add:

ruby
<% content_for :head do %>
  <meta http-equiv="refresh" content="5"><!-- refresh every 5s -->
<% end %>

into the else branch (the one with <pre><%= @snippet.plain_code %></pre>) that displays the plain code when the highlighted version is not available.

If you wan't a progress bar, you certainly would have to use some javascript, and have the worker in charge of the background processing to update some attribute with its progress.