Skip to content

Instantly share code, notes, and snippets.

View universal's full-sized avatar

Johannes / universa1 universal

View GitHub Profile
show do
panel "Participated Surveys" do
farmer_id = resource.id
table_for resource.forms do
column("Name") {|form| link_to(form.name, admin_form_path(form))}
column("Answers") { |form| link_to("answers", farmer_form_question_answers_admin_form_path(form, farmer_id: farmer_id))}
column :created_at
end
@universal
universal / model.rb
Last active August 29, 2015 14:25
Time.now and rails scopes
#Rails 3.2.x model code
class Model < ActiveRecord::Base
#option 1 -- will cache the Time.now value!
scope :expired, where('expire_date < ?', Time.now)
#option 2 -- re-evaluates every time!
scope :expired, -> { where('expire_date < ?', Time.now) }
%div{class: "col-sm-12 affiliation-addresses"}
.col-xs-6.col-sm-6.col-md-6
%div{:class => "form-group"}
=f.label :category, :class => "control-label"
=f.select(:category, [['Mail', 'mail'], ['Business', 'business']], {}, :class => "form-control")
.small-field-error=field_validation_message(affiliation_address, :category)
.col-xs-6.col-sm-6.col-md-6
%div{:class => "form-group"}
=f.label :cep, :class => "control-label"
=f.text_field(:cep, :class => "form-control")
raw_params =
{:user=>
{:a=>"a",
:b=>
[{:c=>"c", :d=>"d"},
{:c=>"c", :d=>"d"},
{:c=>"c", :d=>"d"},
{:c=>"c", :d=>"d"},
{:c=>"c", :d=>"d"}]}}
params = ActionController::Parameters.new(raw_params)
<% blog.tags.each do |tag, articles| %>
<li><%= link_to "#{tag} (#{articles.size})", tag_path(tag) %></li>
<% end %>
# encoding: UTF-8
require 'net/http'
require 'net/https'
require 'uri'
module Literature
class BibliographyDownloader
def self.download
uri = URI.parse(WebsitePrep.config.svn_url)
base = Net::HTTP.new(uri.host, uri.port)
<nav class="navbar navbar-default">
<div class="container-fluid">
<%= link_to root_path, :class => "navbar-brand" do %>
<%= image_tag("slogo.svg") %>
<% end %>
<div>
<ul class="nav navbar-nav navbar-right">
<li>
<%=link_to "Home", root_path%>
</li>
[4] pry(main)> Topic.connection.object_id
=> 84952140
[5] pry(main)> Questionnaire.connection.object_id
=> 84952140
class WhateverController < ApplicationController
def index
sort_order = ["asc", "desc"].include?(params[:order]) ? params[:order] : 'asc'
sort_by = ["name", "address"].include?(params[:sortby]) ? params[:sortby] : 'name'
@users = User.all.order(sort_by => sort_order)
render 'v1/users/index'
end
end
@universal
universal / console
Created April 22, 2015 12:10
pry -r active_support/core_ext
pry -r active_support/core_ext
/home/jhedtrich/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.0/lib/active_support/number_helper.rb:3:in `<module:NumberHelper>': uninitialized constant ActiveSupport::Autoload (NameError)
from /home/jhedtrich/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.0/lib/active_support/number_helper.rb:2:in `<module:ActiveSupport>'
from /home/jhedtrich/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.0/lib/active_support/number_helper.rb:1:in `<top (required)>'
from /home/jhedtrich/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.0/lib/active_support/core_ext/numeric/conversions.rb:2:in `require'
from /home/jhedtrich/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.0/lib/active_support/core_ext/numeric/conversions.rb:2:in `<top (required)>'
from /home/jhedtrich/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.0/lib/active_support/core_ext/numeric.rb:3:in `require'
from /home/jhedtrich/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.0/lib/active_support/core_ext/numeric.rb:3:in `<top (required)>'
from /home/j