Skip to content

Instantly share code, notes, and snippets.

<% if @post.errors.any? %>
var errors = '';
<% @comment.errors.full_messages.each do |error| %>
errors.append("<%= escape_javascript( error ) %>\n");
<% end %>
alert(errors);
<% else %>
$('#posts').prepend('<%=j render 'chapters/posts/post', {:post => @post} %>')
<% end %>
<% if @post.errors.any? %>
var errors = '';
<% @comment.errors.full_messages.each do |error| %>
errors.append("<%= escape_javascript( error ) %>\n");
<% end %>
alert(errors);
<% else %>
$('#posts').prepend('<%=j render 'chapters/posts/post', {:post => @post} %>')
<% end %>
@arjan0307
arjan0307 / conversation.rb
Created March 20, 2012 15:29
Nested forms
class Conversation < ActiveRecord::Base
has_many :messages
has_many :participants
has_many :users, :through => :participants
accepts_nested_attributes_for :messages
end
@arjan0307
arjan0307 / devise.rb
Created April 4, 2012 14:19
E-mails with empty bodies, by devise
# config/initializers/devise.rb
config.mailer = DeviseMailer
@posts = @profile.posts # []
@profile.posts.build
@posts # array containing a single post
@arjan0307
arjan0307 / routes
Created May 17, 2012 15:24
Nested routes without parent routes
# How to get just the comment routes, and not the post routes
resources :posts do
resources :comments
end
@arjan0307
arjan0307 / routes
Created May 17, 2012 15:24
Nested routes without parent routes
# How to get just the comment routes, and not the post routes
resources :posts do
resources :comments
end
@arjan0307
arjan0307 / development.rb
Last active October 9, 2015 10:28
Gmail email rails
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'gmail.com',
:user_name => 'ommitted!',
:password => 'ommitted!',
:authentication => 'plain',
:enable_starttls_auto => true
}
@arjan0307
arjan0307 / index.html
Last active December 13, 2015 17:19
My first comic
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="http://cmx.io/v/0.1/cmx.css"/>
<script src="http://cmx.io/v/0.1/cmx.js"></script>
<body>
<scene id="scene1">
<label t="translate(0,346)">
<tspan x="0" y="0em">One lazy evening...</tspan>
</label>
<actor t="translate(131,49)" pose="-11,9|-12,135|-10,96|-6,85|-9,72|-11,59|-16,34|-21,9|-6,34|-1,9|42,102|45,140|-56,108|-50,134">
@arjan0307
arjan0307 / application_controller.rb
Created February 15, 2013 10:43
check if we're in game.
class ApplicationController < ActionController::Base
protect_from_forgery
layout :ingame, only: :ingame?
before_filter :authenticate_user!, only: :ingame?
check_authorization if: :ingame?
def ingame?
is_a?(IngameController) || (is_a?(RegistrationsController) && ['edit', 'update'].include?(action_name))
end