Displaying 20 results from an estimated 60000 matches similar to: "Version of Struct for initializing via Hash"
2007 Dec 21
0
pretty neat Mash class (Magic Hash)
class Mash < Hash
def method_missing(name, value=nil)
key = name.to_s.sub(/[=?!]$/,'''').to_sym
self[key] = value if name.to_s[-1,1] == "="
self[key] = Mash.new unless self[key] || value
return self[key]
end
end
Its like OpenStruct...so what can you do?
require ''pp''
m = Mash.new
m.first_name = "john"
m.last_name =
2007 Apr 24
2
remote database ActiveRecord model
Does anyone know how to make a model connect to a remote database and
only for that specific model?
That way I can do the typical CRUD functions on a remote server?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group,
2007 Feb 10
1
calling destory on HABTM clear
I know this is probably stupidly simple, but I can''t seem to figure it
out.
I have a many-to-many association using HABTM. Im trying to clear all
the stuff in the join table and call destroy on all the joined items.
For example if I have a many to many for albums and photos,
def method
album=Album.find(4)
album.photos.clear
# NOW HOW DO I DESTROY ALL THOSE PHOTOS?
end
The things I
2007 Jul 03
5
HOW TO: Easily output alternating item styles via metaprogramming
I always need to apply alternating item styles when outputting a collection,
here''s what I''ve been using recently.
In the app helper I define this method:
def alternate(items,alt=false
items.map{|i| i.class}.each { |k| k.class_eval {attr_accessor :alt}}
items.each { |i| i.alt, alt = alt, !alt }
end
When I call the partial I wrap the collection with this method:
2007 Apr 23
8
rake not working when called through cron
This is currently the contents of "app-backup" in my cron.daily.
--
#!/bin/sh
# Cron Job for Mixbook Code Backup
#
# Updated February 1, 2007
cd /var/rails/beta
rake s3:backup:scm --trace >> /var/rails/beta/log/backup.log
cd /var/rails/beta/log
echo "Backup Successful on" >> backup.log
date >> backup.log
echo "--" >> backup.log
--
When I run
2010 Nov 28
2
converting xml to a OpenStruct
Hi just wondering if there is a easy way to turn an xml entity into a
object like of type OpenStruct where i can access everything like a
property?
It''s kind of like parsing xml, I already know about nokogiri, but I want
to work is a OpenStruct and not a DOM object, does that make sense? =P
--
Kind Regards,
Rajinder Yadav | DevMentor.org | Do Good! ~ Share Freely
GNU/Linux:
2007 May 16
7
return ONLY total_hits without querying from real database
Hey guys,
I know I can run search(q).total_hits, but if I try to put :limit=>0 it
gives me an error. I don''t want it actually query any of the results, I
just want it to tell me how many total_hits I would have if I wanted to
search it.
How can I do this?
--
Posted via http://www.ruby-forum.com/.
2007 Jan 06
2
S3 throwing invalid argument using AWS S3 API
Hello,
Im using the following amazon web service API for S3 :
http://amazon.rubyforge.org/
The problem is that after I establish a connection using
establish_connection!, and try using the "store" command, I keep getting
the following error. However, if I reboot my webrick server, it works
fine for about one hour and then starts throwing this error:
Errno::EINVAL in
2007 Mar 21
2
A real puzzler: attr_accessor / create incompatibility?
Greetings,
I have a problem with attr_accessor and create seemingly being at odds
with each other in my environment. Here is the setup:
A simple class representing a US State (say, Maine for example):
class State < ActiveRecord::Base
attr_accessor(:name, :code)
end
In an IRB session, I type the following and receive the response
included below:
>>
2009 Apr 20
3
xxx.valid? still true after xxx.errors.add(...)?
Hi all
I have the following code in my controller:
if @comment.valid?
captcha_url =
"http://captchator.com/captcha/check_answer/#{captcha_code}/#{@comment.captcha}"
result = open(captcha_url)
unless result.read == "1"
@comment.errors.add(:captcha, "Captcha wurde nicht korrekt
eingegeben")
raise "#{@comment.valid?}"
2006 Nov 04
0
traits-0.9.2 - better living through metaprogramming
URLS
http://rubyforge.org/projects/codeforpeople/
http://codeforpeople.com/lib/ruby/traits
ABOUT
traits.rb is set of attr_* like methods on steroids, caffeine, and botox. it
encourages better living through meta-programming and uniform access
priciples. traits.rb supports smart inheritence of class attributes and a
fistful of hooks for veryifying and munging attr values.
2008 Sep 17
2
AR: add attribute to model
Hi!
Well, I thought this was easy, but for some reason it won''t work...
Here is what I want to do:
I am working on an API to a large database. The basic mapping is done,
but I want to implement some convenience methods that take information
for one object and does some calculations with it. The result should be
accessible as attribute.
So in a simple example:
We have an object that
2007 Sep 27
2
Problem getting "extract" from RDig
Hi All,
I have to have a site wide search for my current application. By search
I mean I have to search the static and the dynamic contents from the
database. I have been searching on this for a while on the net and RDig
seems to be a apt solution. While using it I have encountered a few
problems. I know these might be very basic issues but I have not been
able to figure out what is wrong with
2007 Nov 28
0
OpenHash class I thought I would share...
I love OpenStruct, but it has no ability to iterate over the members.
I had extended it, but recently I use this little class. Anyone see
any issues with it ?
class OpenHash < Hash
def method_missing(name, value=nil)
key = name.to_s.sub(/[=?!]$/,'''').to_sym
self[key] = value if name.to_s[-1,1] == "="
return self[key]
end
end
>> o =
2008 Nov 28
1
Rails Beginner.. NoMethodError
Dear all
I encounter error when I login my Web application
NoMethodError in AdminController#login
undefined method `get_title'' for #<Class:0x63ac78>
Here is part of my code
controller/admin_controller.rb
def login
session[:user_id] = nil
if request.post?
if User.authenticate(params[:name], params[:password])
user = User.find_by_name(params[:name])
2007 Jan 23
3
Someone getting RDig work for Linux?
I got this
root at linux:~# rdig -c configfile
RDig version 0.3.4
using Ferret 0.10.14
added url file:///home/myaccount/documents/
waiting for threads to finish...
root at linux:~# rdig -c configfile -q "Ruby"
RDig version 0.3.4
using Ferret 0.10.14
executing query >Ruby<
Query:
total results: 0
root at linux:~#
my configfile
I changed from config to cfg, because of maybe
2007 Jul 26
1
Lohan the observable
Sorry, that name is a misnomer. However, I was excited to find that Ruby
has a built in Observable module and I''m pretty bored, so I apologize in
advance....
require ''observer''
# one who is observed
class Celebrity
include Observable
attr_accessor :name
attr_reader :is
def is=(val)
@is = val
changed
notify_observers(self)
end
end
# one who
2008 Jun 24
1
cache issue with attr_accessor field
Hi,
I''ve got a model with the following attribute added:
attr_accessor :level
which does not exist in the database. After putting instances of this
model in the cache (using Rails.cache.fetch(''foo'') { Category.all } ),
when I retrieve it back from the cache, then trying to access .level
gives:
undefined method `level'' for #<Category:0x34d50a0>
2007 Apr 28
3
Learning ruby question
I''m having trouble understanding Ruby''s concept of scope. Could
someone explain the difference between the following 2 programs.
They both return the same output "aaaaaaaa", but I''m just not sure
about self in #1. Is self.day and self.title referring to and setting
class variables or are they instance variables? Thanks in advance.
# 1.
class Session
2008 May 17
1
Scope Confusion - Controller iVars in Modules
I''ve created a module to include in a Controller. Basically it works,
but I am expecting methods in the module to have access to instance
variables from the controller, and that appears to not be the case.
Yet, a simple Ruby example says it should be. I''m not sure what''s
different.
Simple Example:
module ShapeStuff
def set_type
@type =