I have problem with mongomapper associations. I have one class names User and other named Model. User has many models but...
user = User.first
=> <User ...
user.models
=> []
Model.find_by_user_id(user.id.to_s)
=> <Model ...
Model.find_by_user_id(user.id.to_s).user == user
=> true
Class code (simplified):
class User
include MongoMap...
I find myself constantly writing what I see as unnecessary code in Ruby when using named arguments for methods.
Take for example the following code:
def my_method(args)
orange = args[:orange]
lemon = args[:lemon]
grapefruit = args[:grapefruit]
# code that uses
# orange, lemon & grapefruit in this format which is way prettie...
I'm new to rails and don't even know if this is the correct way of solving my situation.
I have a "Club" ActiveRecords model which has a "has_many" association to a "Member" model. I want the logged in "Club" to only be able to administrate it's own "Member" so in the beginning of each action in the "Member" model I did something simila...
How do you add span tags to the link below in ruby?
<%= link_to (l(:button_show), {:action => 'show', :path => to_path_param(@path)}, :class => "button") %>
I would like to add the span tags to the link like this:
<a href="/show" class="button"><span>Show</span></a>
...
In a functional test of my Rails app, I want to test where I am redirected to. The expected URL points to an external resource (that means it's not part of my application).
The URL looks like this: https://my.url.com/foo?bar1=xyz&bar2=123
Unfortunately I can't predict the parameters, because they are generated by an external resour...
How do I send a JSON request in ruby? I have a JSON object but I dont think I can just do .send. Do I have to have javascript send the form?
Or can I use the net/http class in ruby?
With header - content type = json and body the json object?
Thanks
...
I'm new to Rails (and ruby). What is the standard way of iterating through an array to total a variable.
e.g. for the total expenses in a month, first an Array:
expenses_this_month = expenses.find :all,
:conditions => ['date >= ? and date <= ?',
Date.today.begin...
The Ruby mixin module I'm writing would be useful for both vanilla Ruby and Rails. What's the best practice for determining at run-time whether Rails is loaded? Is it possible to get the version number as well?
In script/console for a Rails 2.3.4 project ENV.has_key?("RAILS_ENV") is true and it's false in my Ruby 1.8.7 interpreter. I...
I've been using Ruby for a while now, and I keep seeing this:
foo ||= bar
What is it?
...
I was trying to limit the instantiation of a class to just a single one(without using singleton) but i couldn't. I tried with class variables (@@) but without luck.
I googled it and came across this:
class A
@count = 0
class << self
attr_accessor :count
end
def initialize val
@a = val
self.class.count += 1
...
Hello there Stackoverflow people,
I run a site that finds its users the cheapest place to buy books. This is easy for a single book, but for multiple books it can sometimes be cheaper to purchase one book at one store and another book from another store.
Currently I find the cheapest store that sells all books in the user's list, but I...
Hi there,
I'm looking for some solutions to BDD a new Shoes app. Any suggestions
...
i have a php file which regularly writes and reads tables from mysql DB.
i have another ruby file that runs at the same time which reads and write to the same tables in mysql DB.
can there be potential issues with this set up ?
...
How to connect to SQL Server 2005 database through Ruby in Windows
...
The idea would be to replace ERB with templates that are pure XHTML and that the view would be pure code manipulating the template content.
Have this been done already ?
...
when I run rails console in netbeans6.8(Ruby on Rails) then getting following error ?
'irb.bat' is not recognized as an internal or external command,
operable program or batch file.
what I need to do for this ?
...
Hi,
I'm using Cucumber to test a PHP application, and while most everything works without issue, I haven't yet figured out how to retrieve a response object for a request -- I'm looking to test whether a response is successful (code 200) and also to perform some Hpricot parsings of the response body.
Right now my env.rb file is pretty ...
I have this to calling the choose_category:
<% form_remote_tag :url => { :action => :choose_category, :id => category } do %> <%= submit_tag category.name%>
<% end %>
And I have this method to calling the choose_category.js.rjs:
def choose_category
begin
category = Category.find(params[:id])
rescue
...
Hi,
I'm new at ruby on rails, and I've noticed that when I send an email, my site_name and site_url vars are not being recognized from the mailer files.
In my config.yml file I've got the following:
development: &local
site_name: my site name
site_url: http://localhost:8282
company_name: my company name
admin_email: a...
What is the most awesome gem I should use to call Erlang functions from Ruby app? I wish to use rspec for testing some gen_server stuff.
Erlectricity looking solid, but there is no something like Node#rpc, just message passing. Any ideas?
...