Skip to content

Instantly share code, notes, and snippets.

View JonasNielsen's full-sized avatar

Jonas Bylov JonasNielsen

View GitHub Profile
= form_for([:admin, @stencil]) do |f|
- if @stencil.errors.any?
#error_explanation
%h2
= pluralize(@stencil.errors.count, "error")
prohibited this stencil from being saved:
%ul
- @stencil.errors.full_messages.each do |msg|
%li= msg
.field
/* FORM */
<form action="/topics" id="new_topic_form" method="post" onsubmit="new Ajax.Request('/topics', {asynchronous:true, evalScripts:true, method:'post', onComplete:function(request){Form.Element.enable('add_topic_submit')}, onLoading:function(request){Form.Element.disable('add_topic_submit')}, parameters:Form.serialize(this)}); return false;">
<div style="margin:0;padding:0;display:inline">
<input name="authenticity_token" type="hidden" value="6sukkqZzoOtj09Z/vJvkgn00m5PrbdjG3n7DFffaQA0=" />
</div>
<input id="topic_slideshow_id" name="topic[slideshow_id]" type="hidden" value="107" />
<label for="topic_title">Title</label>
<br />
<input id="new_topic_title_field" name="topic[title]" size="30" type="text" />
<br />
@JonasNielsen
JonasNielsen / less_full_error_messages.rb
Created April 27, 2010 20:32
Altering error messages to only show the attribute name in the error message, if the error message starts with a lower-case character
# Put this file with your initializers
# Altering error messages to only show the attribute name in the error message,
# if the error message starts with a lower-case character
if RAILS_GEM_VERSION =~ /^2\.3\.5/
class ActiveRecord::Error
def full_message
if attribute.to_s == 'base' || message =~ /^[[:upper:]]/
message
def waiting?
if status == "waiting"
true
else
false
end
end
- if client.is_company?
- hide = ""
- else
- hide = "hidden"
#company_information{:class => "#{hide}"}
%div
%br/
= f.label :company_name
%br/
# IN RJS
page.replace_html "client_informations", :partial => 'shared/client_billing_form', :locals => {:client => @client}
# IN _client_billing_form
%p
= remote_form_for client, :controller => 'clients', :action =>'update_billing_from_editor', :id => client.id, :method => :put do |f|
= render :partial => 'shared/client_billing_info_fields', :locals => {:f => f, :client => client}
%br
= f.submit "Correct Informations", :class => "button green"
respond_to do |format|
format.html { do_your_counting here }
end
class User < ActiveRecord::Base
belongs_to :userable, :polymorphic => true
end
class Designer < ActiveRecord::Base
has_one :user_login, :as => :userable
accepts_nested_attributes_for :user_login
end
class DesignersController < ApplicationController
class Designer < ActiveRecord::Base
has_one :login, :as => :user, :dependent => :destroy
accepts_nested_attributes_for :login
end
puts 'Enter a starting year:'
startingyear= gets.chomp
puts 'Starting year is now ' + startingyear
puts 'Now enter an ending year'
endingyear = gets.chomp
puts 'Ending year is now ' + endingyear
startingyear.to_i.upto(endingyear.to_i) do |i|
if(i % 4 == 0 AND i % 100 != 0)
puts i