ruby-on-rails

Rails - Make a one-off query to a different database and table.

Hi, I have a rails app with a wordpress blog sellotaped on the side (totally separately at /blog). The client want's to the latest blog post on the main homepage of the rails app, so I need to do a one-off mysql query to the word-press database. How would I go about doing this in the rails app. The word-press is completely sperate from...

Mapping multiple domain names to different resources in a Rails app

The rails app I have allows users to manage holiday homes. Each property has it's own "website/homepage" within my app and a user can tweak the content, it works well, quite pleased so far. Typical rails approach to the resources so the URLs to a particular property look like this for the "homepage" of a particular property. localhost:3...

ActiveRecord/MySQL query to return grouped set of objects

I have a model called a Statement that belongs to a Member. Given an array of members, I want to create a query that will return the most recent statement for each of those members (preferably in one nice clean query). I thought I might be able to achieve this using group and order - something like: # @members is already in an array @...

Problem using Resque, Rails 3 and Active-Recored

I have this Class which response to perform to be run by "Resque", I have an error at this line recipient.response = response.body wich is undefined method response=' for #<Hash:0x00000003969da0> I think that because the worker and ActiveRecord can't work together. P.S I already loaded my environment and this class placed in lib directo...

Rails parallel background processing

I have a rails application (which acts like some sort of load balancer for a group of printers) that needs to do some background processing. The background processing logic needs to iterate over all available (non busy) printers and send a print job via TCP socket to each one as long as there are jobs present. I know there are several s...

Rails 3 ActiveRecord associated collections custom methods

If I have an Auction record, which has many Bids associated with it, out of the box I can do things like: highest_bid = auction.bids.last(:all, :order => :amount) But if I want to make this clearer (since it's used in multiple areas in the code), where would I define the method: highest_bid = auction.bids.highest_bid Is this actual...

How do i provide chunked transfer encoding

Sorry for asking this again but i did n't get any answer so i am asking ,i have rails application thats uploading some large file (2gb) but these upload are only possible with google chrome but using Internetexplorer only 1 gb of file being uploaded after that meas more than 1.5 gb IE throwing saying like Internet Explorer cannot displa...

find(params) : ActionView::TemplateError (undefined method 'each' for #haus)

Hi all, I have a controller that has a value that I want to pass to the rhtml. I already managed to get the value correctly, and based on that, I need to do an action in the rhtml. For code snippets, def getsubtable @subtables = Haus.find(params[:bewohner_id]) from the method above, when I debugged it, I can get the correct v...

Subdomains vs Directories for Account has many Users

I am making an app where several users work towards a common goal grouped under an account. What would be a better structure for my urls? Subdomains: some-team-name.app.com Directories: app.com/some-team-name For example, Basecamp uses subdomains. Do clients think better of your web-app if it uses subdomains? In my humble opinion it...

My form fields are being deleted on submit

And as a result its not passing validation. This is my embedded form : - form_for [@organization, @referral] do |f| = f.error_messages = render :partial => 'referral_fields', :locals => { :f => f } = f.submit "Submit", :class => "button" #_referral_fields.html.haml .grid_7 .grid_1{:style => "width: 64px;"} = f.label :o...

Should I use Rails 2.2 vs Rails 3 for learning?

Frustratingly my laptop has Rails 3 on it, although I cannot find much supporting documentation on how to use Rails 3, excepting the API reference. There appears to be a significant amount about regarding rails 2.2. Would you recommend downgrading and learning 2.2 or just plough ahead with 3 and hope for the best? ...

is there a fork of jRails that works with Rails 2.3 and jQuery 1.4 ?

We're rewriting a site using Rails, and the old site makes extensive use of jQuery v1.4 in its templates. We'd like the old scripts to keep working, but we'd also like to use rails' javascript helpers for our own new scripts. jRails sounds like what we want, but it only seems to support jQuery 1.3. Is there a more up-to-date fork of j...

Memcache for pagination

This feels like a really bad idea on implementation and I'm not sure of the speed savings given the potential cost in memory. Using Dalli and Memecache to store a set of data that gets pulled on every page request that needs to be paginated. Its a lot of data so I'd really rather not keep hitting the database if possible, but I also don...

Rails notification messages in Rails 3?

Hi all- I have an application which has achievements that users can earn. I'd like to display these achievements when a user earns them. The system_messages plugin as rec'd here seems to be perfect, but it is not compatible with rails 3. Are there any rails 3 alternatives that would fit the bill, or am I stuck reinventing the wheel? ...

[Rails] I18n doesn't translate in models through cucumber

Hello, My cucumber scenario tests if my news can be create without a title. This must show "You must specify a title.". In my news model, I have: validates_presence_of :title, :message => I18n.t(:specify, :what => 'a title') and in my en.yml have got : specify: "You must specify %{what}." but when I run my test, the result is "...

Rail 3: ActiveRecord plugin methods not available from rake

I am using the import_with_load_data_in_file plugin to load large amounts of data quickly. It works fine in console. However, when calling it from a Rake task, I get: undefined method `import_with_load_data_in_file' for #<Class:0x1038cd9e0> That doesn't really make any sense. The plugin is installed, it's included in the model, and ...

Using Paperclip with files already on Amazon s3

Hi guys, I am building a Rails application that works with videos. I am using an encoding service that encodes my video and places the encoded file along with some thumbnails in a specified location on my s3. I am able to access the video via AWS:S3 like so: AWS::S3::S3Object.find 'videos/36/base/video.mp4', 'my-bucket-name' -- or -...

Can't use ActiveRecord associations Rails 3 in IRB

I have three classes with the following associations: class Technician < ActiveRecord::Base has_many :tickets has_many :services, :through => :tickets end class Ticket < ActiveRecord::Base belongs_to :technician has_many :services end class Service < ActiveRecord::Base belongs_to :ticket belongs_to :technicians end W...

How do I test that a 301 redirect takes place with rspec?

I need to test two things: that certain old paths are correctly redirected to certain new paths that the redirect is a 301, not a 302. I'm using Capybara for my acceptance tests, but that can't handle #2. I can test that the redirect happens, but it happens silently, so I can't see that it was a 301. Controller tests can't handle #...

Rails3 - Given a Form that allows for Updating/Creating - How Delete/Destroy a record?

I have the following for which allows for creating or updating a record: <%=form_for [:project, @permission], :remote => true do |f| %> ... You can change roles in the form... (This works great for new or existing records) <% end %> Inside the form, I want to provide an option to delete/destroy the permission. So I added: <%= link_t...