ruby-on-rails

Inheritance with MongoMapper: searching the parent class

does it make sense to save the class name in a field when using inheritance with mongomapper/rails? class Item include MongoMapper::Document timestamps! key :class, String # does this actually make sense? key :title, String end class Post < Item key :body1, String end class Page < Item key :body2, String end if a sear...

Ruby spreadshet gem, how can I center align a number

I'm using http://spreadsheet.rubyforge.org to generate a spreadsheet and I'm having trouble with something. I'm opening an existing workbook and adding data to it. I have manged to get number formatting working to some extent, at least excel is seeing this data as a number, but (very un-excel like) the client would like the number align...

How to send raw post data in a Rails functional test?

I'm looking to send raw post data (e.g. unparamaterized json) to one of my controllers for testing: class LegacyOrderUpdateControllerTest < ActionController::TestCase test "sending json" do post :index, '{"foo":"bar", "bool":true}' end end but this gives me a NoMethodError: undefined method `symbolize_keys' for #<String:0x00000102...

Building a polymorphic model controller path with has_many

I have a polymorphic model Comment that can be related to many types of commentables. in my routs, for example I have: map.resources :newsitems do |news| news.resources :comments end everything is working fine, the only problem is to generate the paths. I've in my views/controller the @commentable item, that i retrieve from a before...

Filter cached DB queries from Rails' logs?

Is it possible to filter out DB queries that hit Rails' query cache from Rails logs? The presence of these "queries" makes it harder to debug performance issues ...

Nested named scopes with joins (explosive error)

So I have an ActiveRecord class with a couple different named scopes that include join parameters. While running a report, I happen to have a situation where one gets called inside of the other: 1 Model.scope_with_some_joins.find_in_batches do |models| 2 models.each do |mdl| 3 other_comparisons = Model.scope_with_other_joins 4 ...

accepts_nested_attributes_for and select tag

Hi, I've a Room model and a Person model. A room can have many person and a person can have one room. On the room creation screen I can 'link' n person to this new room So i want to have a variable amount of select tag which contains the list of all people I don't know how to build the select tag. Can anyone help thanks... I've th...

Prawn & Prawnto Rails PDF generation - UTF-8 ??

I'm using ruby, prawn, and prawnto to dynamically generate pdf's containing text in other languages. I can't seem to get any text in languages with non-english characters to show up. It doesn't throw any errors...just shows a bunch of dashes instead of characters. Prawn brags on its homepage about UTF-8 support so I don't see why this is...

Association Problem

I am having a problem with an association: Battalion :has_many soldiers Soldiers :has_many primaries I need to do this @bseniorleads=(@user.battalion.soldiers.find(:all, :conditions => ["seniorleader = ?", "Yes"])) then @seniorspouse=(@bseniorleads.primaries.find(:all, :conditions => ["relationship = ?", "Spouse"] This ...

ActiveRecord and Oracle bind variables

We have decided to use Rails/Oracle for a new project. My understanding is that ActiveRecord does not support bind variables and that this hamstrings Oracle's ability to cache queries and leads to significant performance problems. Cursor sharing has been said to help, but not completely, solve this problem. If this description is reas...

How to exclude specific fields from a Rails XML output

I am working on a RoR project which outputs XML to RESTful requests. The problem is it includes the "updated-at" and "created-at" fields in the output. I have tried using: :exclude -> [ :created_at, :updated_at ] and :exclude -> [ 'created-at', 'updated-at' ] but the output still renders them. How do I exclude them from the ren...

Force Ruby Version

I just got burned because I used find_index on an array on my dev box (OSX with Ruby 1.8.7) and the deployment machine runs Ruby 1.8.6. (What's the difference between find_index and index? The latter works on 1.8.7 and 1.8.6) So that got me thinking: what's the best way to force Rails to run with a specific Ruby version? Since it's pr...

commenting with login w/twitter or facebook connect

Im building my blog in rails and I want to enable comments I would like to have something posterous-like with a "facebook connect" and "login with twitter" option. The user can login with one of them and then post. No anonymous posts. I dont want to add more login-services, just stay simple (i.e. no disqus) How can I do this? ...

Rails: Ajax form validations with error_message_on

I've been trying to get get some ajax validations going in my form and have been running into a bit of trouble I have code like this in my form: <% form_for @user, :html => { :id => 'user_form', :multipart => true } do |f| %> <%= f.label :username %><br /> <%= f.text_field :username %> <%= error_message_on :user, :username %> ...

heroku rake migrate not working

I am just trying to simply do the following: my@ubuntu-lappy:~/rails/app_soft$ heroku rake db:migrate rake aborted! Please install the adapter: `gem install activerecord--adapter` (no such file to load -- active_record/connection_adapters/_adapter) What am i doing wrong? In the past I've successfully ran heroku rake db:migrate gem ...

Processing incoming emails on Heroku

For my side project kwiqi, I use ActionMailer's 'receive' method to process incoming email messages for tracking my expenses. Heroku doesn't have a local mail server running that same code will not work. One solution I've thought of is to periodically hit a controller action that will pull messages from Gmail. Are there other solution...

Ruby Style Question: storing hash constant with different possible values

This is more of a style question, I'm wondering what other people do. Let's say I have a field in my database called "status" for a blog post. And I want it to have several possible values, like "draft", "awaiting review", and "posted", just as an example. Obviously we don't want to "hard code" in these magic values each time, that w...

how to submit a form and send fields that are not in the form tag

I am trying to get a form like this: Name form: <% form_tag do %> <p> <label for="name">Name:</label> <%= text_field_tag :search%> <%= submit_tag "Go"%> </p> <% end %> Phone Number <% form_tag do %> <p> <label for="ph">Phone Number:</label> <%= text_field_tag :phone...

? in routes.rb with map.with_options ruby

Hi guys, I'm using named routes in my ruby code. I come from the phpworld where you'll pass information using $_GET and $_POST. I was wondering if there's a way to put this into the routes.rb like this: map.with_options :controller => 'test' do |m| m.someurl 'someurl?search=someterm', :action => 'index' end Currently it's returni...

Converting binary IOstream into file

I am using rails server. i am sending core http request. in request.body contents a file which I want to be uploaded. This request.body is StringIo object. I want to upload this file to my server. ...