ruby-on-rails

is there better way to count for three level nested forms

I have a nested forms like: class House < ActiveRecord::Base has_many :rooms accepts_nested_attributes_for :rooms attr_accessible :rooms_attributes end class Room < ActiveRecord::Base has_one :tv accepts_nested_attributes_for :tv attr_accessible :tv_attributes end class Tv belongs_to :user attr_accessible :manufactur...

`/usr/bin/file -i SOME_FILE` returns different result when deployed to Phusion Passenger

I'm using /usr/bin/file -i SOME_FILE to detect whether it contains non-ascii-and-utf characters. However, it produces different result when the application is deployed to apache+passenger. In 'script/console', above line gives: SOME_FILE: text/plain; charset=utf-8 In passenger, it gives: SOME_FILE: regular file Since I am pointing ...

Unit testing an OpenID server

Hello, I'm currently working on an authentication system derived of OpenID. I work in Ruby and I use the ruby-openid library. Currently, for my tests, I use fakeweb to fake an openid consumer and server and check everything works well. But I don't like the way I do it. And I'm sure there'd be a much better way to do so. So my question...

In Rails how can I get the contents of a page without making an HTTP request?

This may be really obvious, but in rails how can I get the contents of a page without making an HTTP request? i.e. I want to grab the contents of any page that my rails app generates, in a script on the same server. This is of course trivial with an HTTP request, but how can I get the contents of a page otherwise? This is what I am doi...

Rails, Rest - how to get post data from ajax calls

Hi. I am developing rest app in Rails and I have a problem. I send ajax post request to rails rest app update_feedback : function(attrs, success, error){ $.ajax({ url: '/sync/feedback', type: 'post', dataType: 'json', success: success, error: error, data: attrs, fixture: f...

Rails Eager Loading on All Finds

OK, I've been playing around with some of the eager loading things, and have 2 models something like: Class Recipe < ActiveRecord::Base belongs_to :cookbook has_many :recipetags end and Class Cookbook < ActiveRecord::Base has_many :recipes, :include => [:recipetags] end Which is working out well, when I find a Cookboo...

How to handle the event when the selected item changes in an HTML select

Hi, I currently have two Ruby selects: one for categories and the other one for subcategories. As you may anticipate, the second one has to update itself every time the first one changes. For example, if I select from the first one the category "Sports", the second select should load all the sports. How can I handle that "index change...

Custom model attribute (column name) title in Ruby on Rails

Can I add custom model attribute titles, so forms could automatically render them instead of "prettied" column name? For example I apply some method in my model, which defines attribute title: imaginary_method_which_defines_attribute_title :description, "Aprašymas" So I do not need to write title in every form label helper: <%= f.la...

Overriding Rails Error (Validation) Messages from Gems/Plugins

Is there a generally accepted way of overriding error (validation) messages from a gem/plugin in rails? For example, I'm using the ActiveMerchant gem, and if someone puts in an American Express credit card number, but selects 'MasterCard', I get a not-very-descriptive "Type is not the correct card type" error. I can easily get around t...

default to text in a search for with ruby and rails

I want to have a text value for a form like "search website.com..." but if the form has been submitted i want the query to appear- i dont know ruby idioms that well but i was think <%= text_field_tag "q", params[:q] | "search website.com...." %> is this correct? ...

Is it possible to specify columns that should not be loaded in ActiveRecord?

I've got a database table that is shared with another application. It has many columns that I will never use in my application. Is it possible to specify columns to be ignored in the ActiveRecord model? Usually it's not too big of a deal, but in this case I've got a table with two blobs that I'll never need joined with another table ...

Getting count of elements by `created_at` by day in a given month.

I wanted to make a simple chart of users that have been created in the past month in my app. Like basically for each day in the past month I want to show the count of users that have registered that day. What I have so far: # Controller @users = User.count(:order => 'DATE(created_at) DESC', :group => ["DATE(created_at)"]) # View <% @us...

DES3 decryption in Ruby on Rails

My RoR server receives a string, that was encrypted in C++ application using des3 with base64 encoding The cipher object is created so: cipher = OpenSSL::Cipher::Cipher::new("des3") cipher.key = key_str cipher.iv = iv_str key_str and iv_str: are string representations of key and initialization vector for encryption algorithm. They a...

Don't stop on Rails TestTask failure

I'm adding a test task in my Rakefile, similar to this: namespace :test do desc "Test lib source" Rake::TestTask.new(:lib) do |t| t.libs << "test" t.pattern = 'test/lib/*/_test.rb' t.verbose = true end end and then adding (have also done using "enhance" with the same result: task :test => [ 'test:lib' ] My problem is...

mysql pivot to a postgres pivot table...

I was using mysql just fine until I recently switched one of my rails apps to heroku and had to change over. Almost everything works as expected except I have one query which does something totally funky. This is the postgres, but under mysql it is mostly identical except for the EXTRACT DOW and some group by additions, but that isn't ...

What does RJS stand for?

What do the letters RJS stand for? Is it as simple as Rails Java Script? ...

Rails Search Across Multiple Models

Hi I have an issue. I have a show view that acts as a dashboard and brings in records from other models and then models associated to that. I have a simple search form that is working fine to search through one model, but I don't know how to have it look through its associated models as well. I don't think a full text search is necessary...

formtastic - how to prepopulate a string input with a value

I'm building an app, where users can give comments by just leaving their email to the comment. I want them to be able to register directly from there, by a link with their email adress as a param (like: <%= link_to register_path(:email => @comment.email %> ) - so there is no existing user record yet. this should be done by applying a va...

How to decode Rijndael in ruby (encoded in VB.net)

Hello, I am using Rinjael to encode in VB.NET and need to decode in Ruby. My VB.NET encryption class looks like this: Private Class Encryptor Private symmetricKey As System.Security.Cryptography.RijndaelManaged Private iVector As Byte() Private Key As Byte() Public Function encrypt(ByVal data As String) ...

How do I toggle link states when clicked with AJAX and Rails?

In one of my index actions I want to display a link that says either "activate" or "de-activate", depending on whether the record is active or not. When the user clicks on an "activate" or "de-activate" link for a particular record, a call should be made to my update action that updates the record accordingly, and if the link said "acti...