I need a "I accept terms of service" checkbox on a page, it has to be checked in order for the order to proceed. It seems hence illogical to have a column in the database to match this (whether user has accepted or declined terms).
I am using the form helper like this in my view:
<%= check_box("client", "terms") %>
And in my model:
...
I have a class and a hash. How can I get the members of the hash to dynamically become methods on the class with the key as the method name?
class User
def initialize
@attributes = {"sn" => "Doe", "givenName" => "John"}
end
end
For example, I would like to be able to have the following output Doe:
u = User.new
puts u.sn
I'm...
Hi guys! I would like to make a Rails app to create a pretty download page for any file requested either through a link or by typing the url of the file. Is there a way to intercept the request for a file in Apache or elsewhere and send it to the app so it can generate the page?
I'd also prefer not to change the url when redirecting to ...
While using ruby-prof, printed out in graph-html mode, the report for one method says (with some snipping)
%Total %Self Total Self Wait Child Calls Name Line
52.85% 0.00% 51.22 0.00 0.00 51.22 1 ClassName#method_name 42
51.22 0.00 0.0...
I'm trying to get my computer (Mac OS X, running Leopard) running with the latest version of Rails. Before this, I had 2.3.5. I tried following some instructions a few days ago, but didn't seem to make much progress. Now, I can't do anything in Rails. You'll see what I mean in a sec.
Theoretically, I've got the latest versions of Ruby:
...
Consider the following code:
x = 4
y = 5
z = (y + x)
puts z
As you'd expect, the output is 9. If you introduce a newline:
x = 4
y = 5
z = y
+ x
puts z
Then it outputs 5. This makes sense, because it's interpreted as two separate statements (z = y and +x).
However, I don't understand how it works when you have a newline within pa...
Ruby/Rails does lots of cool stuff when it comes to sugar for basic things, and I think there's a very common scenario that I was wondering if anyone has done a helper or something similar for.
a = Array.new(5, 1)
a.each_with_index do |x, i|
if i == 0
print x+1
elsif i == (a.length - 1)
print x*10
els...
I have two array I need to merge, and using the Union (|) operator is PAINFULLY slow.. are there any other ways to accomplish an array merge?
Also, the arrays are filled with objects, not strings.
An Example of the objects within the array
#<Article
id: 1,
xml_document_id: 1,
source: "<article><domain>events.waikato.ac</domain...
I've some huge text files to process and make sense out of the data. Part of the task is to save this data into a database. I want to use Ruby, with postgres or mysql, postgres being the first choice. What libraries should I include? There is no model, its going to be plain SQL statements. How to do this without rails?
...
I have a shoulda macro/method that tests controller responses for XPath conditions like so:
def self.should_have_xpath(path, &block)
should "have an element matching the path: #{path}" do
xml = REXML::Document.new @response.body
match = XPath.match(xml, path)
if block_given?
yield match
else
assert match.si...
I'm a newbie to Ruby on Rails. My problem is, I am trying to upgrade the rails version from 1.2.3 to 2.3.4.
I changed the .rhtml files to .html.erb according to the rails version 2.3.4. I changed the environment and boot.rb settings according to the rails version, but when I try to run the application, I'am getting missing template err...
I dont know the correct terminology for what i am asking
I tried to google it and couldnt ind anything for the same reason
I am writing a ruby library, and i want to rewite the functions so they work as below as i prefer it for readability (inside a block?)
at the moment i have a function that does this
@dwg = Dwg.new("test.dwg")
@dwg...
Hi,
Currently we have a web application written in the providers own proprietary language / framework. Unfortunately, with it's limited syntax and "wonky" architecture its not great to work with.
With some really great development platforms out there (.NET, PHP, Ruby - note that I know nothing of PHP or Ruby but i've heard they are gre...
Hi all,
I have a ruby class that extends Erubis (a ruby templating engine) and I would like to create my own tags. The following is an example of what i'd like to be reproduce:
<%= link_to "/some/url" %>
This code should generate a html 'a' tag linking to some url. Now i'd like to be able to create my own tags such as:
<%= javascrip...
Greetings all...
I'm using OpenLDAP, ActiveLdap and ruby-net-ldap to administer the contents of an LDAP directory. I have most of the things I need working but have been unable to get associations to work (and associations are the reason I'd like to use ActiveLdap; otherwise, I'll just implement associations manually with ruby-net-ldap)...
Hi,
I have an array of hashes, @fathers.
a_father = { "father" => "Bob", "age" => 40 }
@fathers << a_father
a_father = { "father" => "David", "age" => 32 }
@fathers << a_father
a_father = { "father" => "Batman", "age" => 50 }
@fathers << a_father
How can I search this array and return an array of hashes for which a block returns...
I need a client side API in either Java or Ruby. I would much prefer need this to be LOCAL only. Infact this might not even be an IP, but more of a database import. The thing is that I cannot make use of a web service based one as that is too much heavy I/O for me.
Note: By geolocation, all I really need is country/region at best. I wou...
Hi,
i have 3 models
users, companies and roles
User belongs_to role
User has and belong to many companies
Role has_one User
Thru this association i can do something like:
User.companies <-- i get all companies that a user has
User.role <-- i get the role that a user belongs_to
I was thinking now, when a user has role_id == 0 (admin...
I want to use Ruby in Apache through CGI. I have the following in my configuration file:
DocumentRoot /home/ceriak/ruby
<Directory /home/ceriak/ruby>
Options +ExecCGI
AddHandler cgi-script .rb
</Directory>
test.rb is a testfile placed under /home/ceriak/ruby/, #!/usr/bin/ruby included on the first line and given executable pe...
Is there an equivalent to Python's Twisted available in Ruby to abstract common networking protocols and make dealing with TCP/IP sockets generally easier?
...