ruby-on-rails

Adding index to MongoDB causes empty results

Hey all, I have a mondoDB with data in it at the moment which I am querying with Ruby on Rails. I am looking to index the database to speed things up a bit. I read the mongoDB documentation and followed the instructions on how to add a index, like so: db.collection.ensureIndex({"key": 1}) This returns true and returns this in the co...

Formtastic select with grouping

Now with Formtastic I have plain select: = f.input :category, :as => :select, :include_blank => false, :collection => subcategories Here I show only children categories. I use acts_as_tree plugin for parent-child relationship. I would like to show parent categories as well. Formtastic generated select should look like this one: <sel...

Which files should I ignore in subversion for a Rails project

I can see I should ignore tmp/ and log/ but are there any other files which shouldn't be in the repository. ...

What is the difference between link_to and link_to_unless_current

I'm just a beginner using Ruby on Rails for building website.. Here they hv not clearly mentioned the difference between link_to and link_to_unless_current plz help as soon as possible ...

annotated time line

I'm working with google annotated time line graphs: http://code.google.com/apis/visualization/documentation/gallery/annotatedtimeline.html My question is: I would like to limit the X-axis to show just a range of hours between 5:00 and 21:00. Today I'm showing already per hour but I would like to limit the range and not show 24 hours. Is...

Techniques for reducing database queries in a Rails app

If you have a Rail app with many complex associated models, what techniques do you employ to reduce database queries? In fact, I'll extend that question a little further and ask, what do you consider "too many" queries for any page? I have a page that I expect will end up hitting the database about 20 times each page load. That concern...

How do I work around the has_many :through single association restriction?

Given the relations { proposals(id, ...), reviewers(id, ...), comments(id, user_id, proposal_id, ...), votes(id, user_id, proposal_id, ...) } how can I create an association from Vote to Comment? Each reviewer can vote once on a proposal "create unique index on votes(user_id, proposal_id)" and can comment many times. A...

Rails functional tests, routing error

I'm new to testing, and I'm having some difficulties trying to run a functional test. I've a messages_controller, and a user_controller here. in the routes, I've defined that the users resources has_many message resources. Now I'm trying to run a simple test in the messages controller: def test_index get :index, { :user_id => 1 } ...

How to test OpenID in rails with cucumber

How to test OpenID in rails with cucumber. Does anybody have real example? For example by using Fakeweb. Thank's ...

Delayed::Job, Monit and Memory Error

So I've had Delayed::Job running swimmingly in production for a while. Whenever i'd make a change to a job I would (all in the production env mind you) restart delayed job using the [script](http://wiki.github.com/tobi/delayed_job/running-delayedworker-as-a-daemon) i used clear the jobs using `rake jobs:clear` Also, i have monit runn...

Rails - Best way to implement Optionnal Fragment Caching for testing purposes

Hi, I'm using fragment caching a lot and it is essential to me for good performance. However, due to the complexity of the caching I'm using, I need to offer my testers, a way to disable/enable caching as a session variable. (On a user basis only) I was thinking about implementing a cache_disabled? method, and I now check for it's valu...

Rails Plugin|Gem that emails error reports?

can you recommend me a Rails Plugin/Gem that emails error reports? ...

Avoiding repetitive "content_for" in views

I have a submenu placed in my layout wich differs from controller to controller, but not between each controllers method views. What I am currently doing is the following: <% content_for( :submenu ) do %> <%= render :partial => 'submenus/correct_submenu' %> <% end %> In every view for a method My applications layout then has this...

Spawning in Rails

Hello, I was using the spawn plugin (http://rubyforge.org/projects/spawn/) which worked excellent. However, I then moved to Mongo (using mongo_mapper) and Spawn no longer worked. Modifying the plugin is beyond the scope of my abilities. Is there a simple way to do spawning in Rails that would work with Mongo? It's not an often-run proc...

What is the purpose of :conditions on a belongs_to association?

Say I have the following association with an attached condition: belongs_to :admin_user, :class_name => 'User', :foreign_key => :admin_user_id, :conditions=> 'users.admin=TRUE' # or any variation with hash or array, {:admin => true}, etc. The API doc states that the :conditions option on belongs_to will: Specify the...

HTTP request dispatch from Web Server to a CGI/FastCGI process

To gain more understanding of how HTTP requests are handled in case of web apps, how does a web server like Apache, dispatch a request to one of its Virtual Hosts? What are the initial programs executed irrespective of the framework (Rails/PHP/Java)? I would appreciate if someone can list the steps taking example of Rails (as I know Rail...

Rails and jQuery producing 406 error

I am getting 406 Not Acceptable error when submitting my form with jQuery. I have tried the common fix found on the web: jQuery.ajaxSetup({ 'beforeSend': function(xhr) { xhr.setRequestHeader("Accept", "text/javascript"); } }) This hasn't fixed the problem. request.format outputs text/html. I have been racking my brain all d...

Ruby on Rails and db:fixtures:load - can it ignore some models?

I have two databases in use in a Ruby on Rails application; one is the database for the application while the second is an independent database over which Rails is not given control. Problem is when loading fixtures into the dev, it tries to run DELETE statements on the tables in the independent database from the connection to the dev d...

Optimise ignoring of undefined variables when building find conditions in Rails

Hello, I have a an method that retrieves Groups that are present in certain areas. Groups are given a country_id, region_id and city_id The UI gives three select boxes to choose a country, a region from that country and then a city from that region. To find all groups in a particular city, I have this code: @groups = Group.find(:all, ...

validate presence of has_and_belongs_to_many

Hi i'm using a has_and_belongs_to_many in a model. I want set the valitor of presence for kinds. and set the max number of kinds per core to 3 class Core < ActiveRecord::Base has_and_belongs_to_many :kinds, :foreign_key => 'core_id', :association_foreign_key => 'kind_id' end how can i do? thanks ...