Hi,
I am working on a ruby on rails application. For a session controller, I want to use a case to check if a user's account is locked or banned. I am trying to use the object of a class as the case, and use when to check attributes.
For example,
user = Profile.find(1)
case user
when user.ban
redirect_to()
when user.lock
redirect_...
Hi all,
I followed a few rails tutorials online, and it seems that to capture a date, I'd use date_select helper. But for some reason or another all the other data is captured in the database (SQLite3) except for the birthday. Any idea what I'm doing wrong?
Here's the code for the form in my view:
<% form_for :user, :url => {:contr...
hii,,
i would like to know to how to use system("clear") in ruby .
i made a programme like
puts "amit"
system("clear")
i am using scite as compiler and i want console to be cleared after executing this commnad
here its not working. plzzz help me
...
Is there any major difference between load and require in the Ruby on Rails applications? Or do they both have the same functionality?
...
Hello, I've considered making a closed source project, but if I made it then I'd want to make it in Ruby. Ruby is interpreted though. Other similar languages to Ruby include Python and Perl. How would you best distribute your code without giving away all the logic(at least easily readable)? And what about meta programming? Do obfuscaters...
I want to create a tool with Ruby which works with all 3 of the major OSes (Windows, Linux, Mac OS X). What choices do I have for toolkits where the bindings for Ruby is "good"? By good I mean not just quick direct mapping of the C/C++ API onto Ruby, for instance using blocks where appropriate and other Ruby features.
...
Metaprogramming in ruby is great because I constantly use it to emulate prototype based programming and quickly write prototype solutions to some problems to test their viability. So I would like to know if there is any essential difference between the following pieces of code:
(class << some_object; self; end).class_eval do
define_me...
What is green threading means in ruby on rails , what it actually do?
Is it a. " A design where fixed size pool of threads is shared around the program?"
b. "when threads are emulated by virtual machine or interpreter?" or
c. " where program run accross the multiple CPU?"
Please explain with right ans?
...
Basically I am using the MySQL gem for Ruby, and I have no reasonable support for date comparison. The Mysql::Time class only gives me only accessor methods like year, month, second, etc. I could do much better date comparison, if I could turn this into a Ruby DateTime object. How can convert MySQL's DateTime field to a Julian day number...
Let's say i have an array called teams.
I want to plan matches for every team with every other team.
This is almost what i want except that same matches are added twice:
teams.each do |red_team|
teams.each do |blue_team|
if red_team != blue_team
@planned_matches << Match.new(red_team, blue_team)
end
end
end
How to d...
I just wanna give a try on the new frame Padrino. I followed the steps given here.
I am stuck at running the rake tasks.
I used Mysql as my database. I created the project using the command.
padrino g project sample_blog -t shoulda -e haml -c sass -s jquery -d activerecord -a mysql padrino g admin
I have all the dependencies in orde...
I would like to achieve the following by introducing a new operator (e.g. :=)
a := b = {}
b[1] = 2
p a # => {}
p b # => {1=>2}
As far as I understand, I need to modify the Object class, but I don't know what to do in order to get what I want.
require 'superators'
class Object
superator ":=" operand # update, must be: superator ":=...
Ruby's eval() can be like
def showblock(&block)
puts eval("i * 3", block)
end
where block is the block passed into the function.
Instead of a block, a binding object can be passed in as well. Is the binding object the same as what is called the "scope chain" that is mentioned a lot when Javascript closure is discussed?
...
In my project i have this combo box, and it works perfectly:
<%= collection_select @project, @project.clients.id, @project.clients, :id, :name %>
My simple and quick question is, how can i render this in a partial, I'm using this and it's not working...
<%= render :partial => "clients", :collection => @project.clients, :locals => {:p...
I'm attempting to make a connection to external web services (a url shortener, an oauth provider, and exceptional). Nginx+passsenger refuses to create a successful connection, saying the "proxy hungup" or some sort of DNS failure occurred. Apache+passenger had so such issue.
I'm guessing I am failing to configure nginx properly — how ca...
I get the following error while performing the following commmand of adding rubygems.orgs as the gem source.
I am having Windows XP.
C:\>gem source --add http://rubygems.org
Error fetching http://rubygems.org:
SocketError: getaddrinfo: no address associated with hostname. (http://r
ubygems.org/specs.4.8.gz)
Please help me out ...
I wanted to install ruby 1.9.1 instead of the older version so I ran this command on Ubuntu:
sudo apt-get install ruby1.9.1-full
After the install was complete, I got the following error(s):
WARNING: Installing to ~/.gem since /var/lib/gems/1.9.1 and
/var/lib/gems/1.9.1/bin aren't both writable.
WARNING: You don't have /hom...
i am getting error while truing to install watir
C:>gem install watir
ERROR: http://rubygems.org/ does not appear to be a repository
ERROR: Could not find a valid gem 'watir' (>= 0) in any repository
C:>gem -v
1.3.7
C:>ruby -v
ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-mingw32]
...
How do I sort this:
arr = ["aaa","aa","aaaa","a","aaaaa"];
into this
arr = ["a","aa","aaa","aaaa","aaaaa"];
...
In order to implement auto-vivification of Ruby hash, one can employ the following class
class AutoHash < Hash
def initialize(*args)
super()
@update, @update_index = args[0][:update], args[0][:update_key] unless
args.empty?
end
def [](k)
if self.has_key?k
super(k)
else
AutoHash.new(:update => self, :u...