This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Admin::AuditsController < ApplicationController | |
| def create | |
| @audit = Audit.new params[:audit] | |
| if @audit.valid? | |
| # ... | |
| else | |
| render :action => 'new' | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User < ActiveRecord::Base | |
| EMAIL_FORMAT = /\A[a-z0-9][a-z0-9._-]*\z/i.freeze | |
| validates :username, :presence => true, :uniqueness => true, :length => {:minimum => 4, :maximum => 16 }, :format => { :with => EMAIL_FORMAT } | |
| validates :phone_number, :length => {:minimum => 6, :maximum => 25}, :format => { :with => /\A\S[0-9\+\/\(\)\s\-]*\z/i }, :allow_blank => true | |
| #----------------# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # _form.html.erb | |
| <%= form_for @profile do |f| %> | |
| <% if @profile.errors.any? %> | |
| <div id="error_explanation"> | |
| <h2><%= pluralize(@profile.errors.count, "error") %> prohibited this profile from being saved:</h2> | |
| <ul> | |
| <% @profile.errors.full_messages.each do |msg| %> | |
| <li><%= msg %></li> | |
| <% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'logger' | |
| require 'rubygems' | |
| require 'ncurses' | |
| class Ncurses::WINDOW | |
| def initialize( height, width, starty, startx ) | |
| raise 'Boo!' | |
| w = super( height, width, starty, startx ) | |
| w.clear |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create users from csv file | |
| def create_students_from_csv | |
| @csv_file = CSV::Reader.parse(params[:csv_file]) | |
| # Did we get a file? | |
| if @csv_file | |
| # Remove headings | |
| @csv_file.shift | |
| count_saved = @csv_file.inject(0) do |acc, row| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter | |
| def initialize_with_perl_utils(*args) | |
| returning(initialize_without_perl_utils(*args)) do | |
| execute('SELECT prepare_perl_utils()') | |
| end | |
| end | |
| alias_method_chain :initialize, :perl_utils | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter | |
| alias_method :originit, :initialize | |
| def initialize(connection, logger, connection_parameters, config) | |
| ret = originit(connection, logger, connection_parameters, config) | |
| self.execute('SELECT prepare_perl_utils()') | |
| return ret | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1 class CreateSurveyResponseAlternatives < ActiveRecord::Migration | |
| 2 def self.up | |
| 3 create_table :survey_response_alternatives do |t| | |
| 4 t.string :name | |
| 5 t.string :value | |
| 6 t.integer :position | |
| 7 t.references :survey_item | |
| 8 end | |
| 9 | |
| 10 #SurveyResponseAlternative.reset_column_information |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| context "#increment" do | |
| setup { @object.create! } | |
| evaluate { @object.increment! :attribute } | |
| should_change("attribute", :from => 0, :to => 1) { @object.attribute } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## I seem to have lost my base models - I had obtained them already from pre-existing tables. | |
| Basically, this relates to one table, a model and a subclass, which I thought would be quite short. | |
| class Person < ActiveRecord::Base | |
| has_one :address | |
| has_one :phone | |
| belongs_to :district | |
| def member? | |
| mem # and if you really require true/false: !!mem |