match '/lolcat/:id/memeify', to: 'lolcats#memeify', via :post post '/lolcat/:id/memeify', to: 'lolcats#memeify' or... via :get via :put via :delete via :all Also... Generates a bunch of routes. Potential XSS risk!
class UsersController < ApplicationController def create @user = User.create! user_params redirect_to @user end private def user_params params.require(:user).permit(:username, :password) end end
to pass back and forth both a unique content identifier and the timestamp of when the content was last changed. If the browser makes a request where the content identifier (etag) or last modified since timestamp matches the server’s version then the server only needs to send back an empty response with a not modified status. Oh. wat wat
<%= post %> <%end%> <%= cache ['v2', post] do %> <%= post %> <%end%> <%= cache ['v3', post] do %> <%= post %> <%end%> <%= cache ['v4', post] do %> <%= post %> <%end%> Rails 3 caches changes in the model, but not the template, versioning tracks changes in the template
= "text/event-stream" redis = Redis.new redis.subscribe('messages.create') do |on| on.message do |event, data| response.stream.write("data: #{data}\n\n") end end redis.quit response.stream.close end end def create attributes = params.require(:message).permit(:content, :name) @message = Message.create!(attributes) $redis.publish('messages.create', @message.to_json) end
by default) ✤ Write thread-safe code (thread-safe gem, locks) ✤ Web server must support concurrency (e.g. Thin or Puma) in lieu of multi-process servers ✤ Don’t forget to write headers first and close your stream
true) end end if show_posts.any? show_posts.recent else [] end Rails 4 def show_posts if current_user.banned? Post.none else Post.where(published: true) end end show_posts.recent
:tags end resources :articles do resources :comments resources :categories resources :tags end Rails4 concern :sociable do resources :comments resources :categories resources :tags end resources :posts, concerns: :sociable resources :articles, concerns: :sociable Extract common model behavior to concerns via new concerns directory