Skip to content

Instantly share code, notes, and snippets.

@DanCoughlin
DanCoughlin / call me
Created June 28, 2012 12:37
Contact Form
<h1>Contact Form</h1>
<%= form_for(@contact_form, :html => {:class => 'form-horizontal well'}) do |f| %>
<%= f.label :name, 'Name', :class=>"control-label" %>
<div class="controls">
<%= f.text_field :name, :class=>"controls", :value=>"", :required => false %>
<%= f.submit :value => "Send", :class => "btn-primary btn-large" %>
</div>
<% end %>
@DanCoughlin
DanCoughlin / pass me maybe
Created June 27, 2012 19:16
How to conditionally pass a parameter
<%= form_tag catalog_index_path, :method => :get, :id => "search-form-header" do %>
<%= search_as_hidden_fields(:omit_keys => [:q, :search_field, :qt, :page]).html_safe %>
<%= text_field_tag :q, params[:q] unless params[:q] == 'dashboard'?, :class => "q", :id => "search-field-header", :placeholder => "Type keywords in here" %>
<%= params[:controller] %>
<%= submit_tag 'Go', :id=>'search-submit-header' %>
<% end %>
@DanCoughlin
DanCoughlin / monkeypath.rb
Created June 21, 2012 18:22
permissions to prevent updates we don't want
module Hydra
module Datastream
class RightsMetadata < ActiveFedora::NokogiriDatastream
# Updates permissions for all of the persons and groups in a hash
# @param params ex. {"group"=>{"group1"=>"discover","group2"=>"edit"}, "person"=>{"person1"=>"read","person2"=>"discover"}}
# Currently restricts actor type to group or person. Any others will be ignored
def update_permissions(params)
params.fetch("group", {}).each_pair {|group_id, access_level| self.permissions({"group"=>group_id}, access_level)}
#params.fetch("person", {}).each_pair {|group_id, access_level| self.permissions({"person"=>group_id}, access_level)}
@DanCoughlin
DanCoughlin / gist:2962066
Created June 20, 2012 20:38
multi select options
no worky
<%= f.select "resource_type", options_for_select(ScholarSphere::Application::config.resource_types, @generic_file.resource_type), {}, {:multiple=>true, :size=>7} %>
worky
<%= f.select "resource_type", options_for_select(ScholarSphere::Application::config.resource_types, [@generic_file.resource_type.first, @generic_file.resource_type.last]), {}, {:multiple=>true, :size=>7} %>
38 # Groups that user is a member of
39 def groups
40 #Hydra::LDAP.groups_for_user(login + ",dc=psu,dc=edu")
41 return ["umg/up.dlt.gamma-ci", "umg/up.dlt.redmine"]
42 end
@DanCoughlin
DanCoughlin / application.rb
Created May 17, 2012 18:45
issue with facets improperly displaying
config.fits_to_desc_mapping = {
:format_label => :format,
:last_modified => :date_modified,
:original_checksum => :identifier,
:rights_basis => :rights,
:copyright_basis => :rights,
:copyright_note => :rights,
:file_title => :title,
:file_author => :creator,
:file_language => :language
@DanCoughlin
DanCoughlin / OpenSrf
Created December 1, 2010 13:52
Services hanging after multiple calls
# some basic system info
Python 2.6.6
OpenSrf svn checkout from 11/30/2010
> uname -a
Linux capstest 2.6.35-22-server #33-Ubuntu SMP Sun Sep 19 20:48:58 UTC 2010 x86_64 GNU/Linux
>cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.10
DISTRIB_CODENAME=maverick