1 2 3 4
class ProductsController < ApplicationController helper_method :sort_column, :sort_direction ...
1 2 3 4
<% if I18n.locale == :pl %> <%= link_to 'PL', { :locale => :pl }, :class => "language_selected" %> | <%= link_to 'ENG', { :locale => :en } %> <% else %> ...
Ruby Language Selection
Hi, I'm sure this is the mo...
1 2 3 4
def format_category_list(sub_categories) count = sub_categories.count list = "" ...
Ruby Generating a list of 3 entr...
I have this function in my ...
1 2 3 4
uri = URI.parse(the_uri) hash = CGI.parse(uri.query) hash["size"] = size.to_s ...
Ruby Set value of key in uri
Is there some magic i don't...
1 2 3 4
class ItemsController < ApplicationController def create @product = Product.find(params[:product_id]) ...
Ruby Add product to cart, reject...
I've a simple cart applicat...
1 2 3 4
if @user.valid? .... result = create_customer ...
Ruby Redundant Else Clauses
Hi,
I have a controller wh...
1 2 3 4
# link_categories has_many links create_table "link_categories", :force => true do |t| t.string "name" ...
Ruby Find records according to r...
I have a method (LinkCatego...
1 2 3 4
has_many :fight_wins, :class_name => 'Fight', :finder_sql => '#{sanitize_sql_array( "SELECT f.* ...
Ruby Refactor sanitize_sql_array
I can't get this to work pr...
1 2 3
class Store < ActiveRecord::Base has_many :promos ...
Ruby Rails Store has more than m...
Store has many Promos. Prom...
1 2 3 4
def check_win_streak(streak) badge = 10 while badge < BADGE::MAX_STREAK_BADGE_SIZE do # MAX_STREAK_BADGE_SIZE = 30 ...
Ruby how to refactor tricky logi...
The rule at work here is th...
1 2 3 4
class IcalController < ApplicationController ## ...
Ruby iCal subscription
We have a database that con...
1 2 3 4
def verify_admin! unless ((!params[:account_id].blank?) && (params[:account_id].to_i == current_account.id) && (params[:id].to_i == current_member.id)) || current_member.is_admin? flash[:alert] = "Can't access this page" ...
Ruby Rails Security module refac...
I have this method as part ...
1 2 3 4
last_vehicle = Vehicle.find(:first, :order => 'id desc') unless last_vehicle.blank? ...
Ruby Ruby on Rails reverse 'build'
In this scenario, a new Veh...
1 2 3 4
def create # SWFUpload upload if params[:Filedata] ...
Ruby Huge create action
Inherited this from an olde...
1 2 3 4
namespace :vic do desc "Bootstrap RAILS_ROOT/config/enviroment.rb" task :env do ...
Ruby Repeating functions in rake...
How I can remove the duplic...
1 2 3 4
class Activity < ActiveRecord::Base has_and_belongs_to_many :products has_and_belongs_to_many :articles ...
Ruby find_by in two has_and_belo...
Using: Article.first.products
1 2 3 4
# Initial attributes Hash # attributes = { ...
Ruby Ruby Hash Extraction Using ...
I'm looking for a better wa...
1 2 3 4
def update_materials jm = JobMaterial.find(:first, :conditions => {:material_id => params[:job_material][:material_id], :job_id => params[:job_id], :location => params[:job_material][:location]}) if jm ...
Ruby add or increment item count
This is a custom method in ...
1 2 3
def render_page_sitemap(scope, sitemapname,statics, machines, lang) ...
Ruby Speeding up Sitemap generation
Hi,
I'm looking for a wa...
1 2 3
Clip.find_by_sql(["select * from clips where not exists (select 'clip_id' from histories where histories.clip_id = clips.id and histories.user_id = ?) ORDER BY clips.created_at DESC LIMIT 20", user.id])
Ruby ActiveRecord find_by_sql
How can I turn this into so...
1 2 3 4
class Item < ActiveRecord::Base ALL_VOTES = "all_votes" SCORE = "score" ...
Ruby Complex query in Ruby on Ra...
I have a method called rank...
1 2 3 4
def sort if params[:fact_id] @fact = Fact.find_by_id(params[:fact_id]) || Fact.new ...
Ruby Ugly IF, ELSE
Trying to make this a lot c...
1 2 3 4
def merge_query!(options) return unless params[:query] statements = [] ...
Ruby Merging conditions into an ...
This is some controller cod...
1 2 3 4
module PrototypeFaceboxRender def render_to_facebox(options = {}) options[:template] = "#{default_template_name}" if options.empty? ...
Ruby Prototype Facebox Render
I didn't want to add jQuery...
Hi all,
I know that the c...