ruby-on-rails

Saving multiple objects in a single call in rails

I have a method in rails that is doing something like this: a = Foo.new("bar") a.save b = Foo.new("baz") b.save ... x = Foo.new("123", :parent_id => a.id) x.save ... z = Foo.new("zxy", :parent_id => b.id) z.save The problem is this takes longer and longer the more entities I add. I suspect this is because it has to hit the database...

Rails: class' object_id changes after I make a request

I really can't explain this behavior, notice how after I make a request the class' object id has changed, and therefore my is_a? evaluation returns false. any ideas? I'm not even sure how to debug this. Also, this isn't related to making a request from the command line. The same behavior is exhibited on the web server as well, it's just...

Auto switching databases from a rails app gracefully from the ApplicationController?

I've seen this post a few times, but haven't really found the answer to this specific question. I'd like to run a rails application that based on the detected request.host (imagine I have two subdomains points to the same rails app and server ip address: myapp1.domain.com and myapp2.domain.com). I'm trying to have myapp1 use the defaul...

Rails logger messages test.log?

Is it possible to configure rails to show logger.debug messages (from logger.debug statements inside controllers) to display inside test.log (or to the console) when running unit and functional tests? I added the following to test_helper.rb. I see messages from logger.debug statements directly inside tests but no messages from logger st...

jQuery validation plugin: valid() does not work with remote validation ?

I got started by following this awesome tutorial, but wanted to do the validation on on keyup and place my errors somewhere else. The remote validation shows its own error message at the appropriate times, making me think I had it working. But if I ask specifically if a field with remote validation is valid, it says no, actually, its not...

Building Active Record Conditions in an array - private method 'scan' called error

Hi, I'm attempting to build a set of conditions dynamically using an array as suggested in the first answer here: http://stackoverflow.com/questions/1658990/one-or-more-params-in-model-find-conditions-with-ruby-on-rails. However I seem to be doing something incorrectly and I'm not sure if what I'm trying is fundamentally unsound or if I...

Running Rails as an embedded app inside of a gem

I'm trying to understand what exactly the above (in my question's Title) means? This is taken directly from the SpreeCommerce.com project: If you’re an experienced Rails developer you may be wondering where your app directory is. Spree actually runs as an embedded Rails app inside of your gem. How do you customize things then? We’ll cov...

sample/good rails projects to learn from

I am just starting with Rails. I've read through the AWDR book and am currently working on a side project in rails. I want to get an idea of what a good rails project should look like in order to learn what the best practices are. Can you guys point me to some good rails projects on github that not only work well but are well written?...

Grid forms in Rails

I am trying to create a grid form for a survey question. value1 value2 value3 option 1 x option 2 x option 3 x Each cell in the grid is a radio button and the radio buttons in a row belong to one radio button group. My models: class Question # title has_many :answers end class Answ...

Keeping a set of environment variables in rails and javascript

essentially, we want to keep a set of constants to be used across the rails app and javascript code. For example: {A:3 B:4 C:5} We try not to embed rails code in javascript, and we do not want 2 copies of constants. Thanks! ...

Had it with TextMate. Alternatives?

Since Version 1.5.9 (1589) is just too slow and Find in Projects will crash your Mac, I need to find a replacement. Best alternatives as of March 2010? ...

Ruby on Rails + Jquery: Saving data from draggable lists

Hello. I'm trying to save data to the MySQL database in Rails when the user drags items from different lists. I'm using the below Jquery script and HTML: <script> $(document).ready(function() { $("#draggable").draggable( { connectToSortable: 'ul#myList', helper:'clone' } ); $("#myList").sortable(); }); </script> HTML: <ul> <li ...

How do I get autotest (ZenTest) to see my namespaced stuff?

Autotest is supposed to map my tests to a class, I believe. When I have class Foo and class FooTest, autotest should see FooTest and say, "Hey, this test corresponds to the unit Foo, so I'll look for changes there and re-run tests when changes occur." And that works, however... When I have Foo::Bar and Foo::BarTest, autotest doesn't see...

Starting mongrel with a custom command line argument

I would like to be able to start a mongrel or webrick server by passing an extra command line argument that I can read somewhere inside my rails application. An example would be: ruby script/server -p3000 --target=FOO Here, --target is a custom switch who's value I would like to intercept in my rails application. However, this yields...

How to host different applications without subdomains in Heroku?

I would like to have different applications under the same domain using Heroku. Because of the name of the domain, I would like to access the applications using folders (mydomain.com/app) instead of using subdomains (app.mydomain.com), is this possible? Thanks ...

Time.now & Created_at are different? Ruby on Rails

My site is deployed on heroku. Time.now will return today, but the created_at field of a record (created right now) will say its tomorrow. I assume this has to do with server time? Is there a way to make sure they're the same? Best, Elliot Update so I did this "heroku rake time:zones:us" it gave me: * UTC -10:00 * Hawaii * UTC...

has_many inheritance

I have a model called company that has_many users then users belongs_to company. class Company < ActiveRecord::Base has_many :users end class User < ActiveRecord::Base belongs_to :company end If something belongs to users will it also belong to company? ...

Is there an ActiveMerchant for Sinatra?

What payment gateway library works with Sinatra if you're looking to add ecommerce functionality to your app? ...

not unique ids in a route in Rails

In a blog in Rails I want to have paths like http://mydomain.com/posts/28383/comments#21 This is the 21st comment of the 28383th post. The 21 is not an unique id, but the pair 28383, #21 is unique. How can I do this in Rails? Do I have to change the routes? the model? I will be very thankful if you can point me in the right direction ...

Rails: when to use self.

I am developing a Rails application and would like to understand when to use self.for. Here is the code of a method that I would like to fully understand. If it is possible I would like to have an alternative to this code so it would make things more clear. def self.for(facebook_id) User.create_by_facebook_id(facebook_id) end ...