ruby-on-rails

RoR onchange check condition before calling remote_function???

hi i am using remote_function call onchange before calling remote_function i want to check the condition iam using code written below <%= select_tag 'name', options_for_select(search.collect{ |v| [v.name]})+ "-Add Name-", :onchange => remote_function(:url => {:controller => :name, :action => :create_name}) %> here i want...

Set session variable inside plugin model

So I'd like to set/get a session variable from inside a plugin model that I've included to my project. I tried making a method (one getter one setter) inside the application_controller.rb but this did not work. Where can I make getter/setter methods so that a plugin model has access to them? ...

ActiveRecord siblings in many-to-many relationship

I have this working to a degree, but I am looking for some input on how to query for the siblings in a one to many relationship to see if there is a more elegant way of accomplishing this. Consider the following classes class Post < ActiveRecord::Base has_many :post_categories has_many :categories, :through => :post_categories en...

Easiest way to embed flash videos in Rails - must be cross browser compatible

Hi, I need to embed flv, mp4 and possibily other videos in a rails 2.3.5 application. I'm having quite a lot of problems making the videos show up in Safari 5 and Firefox 3.5. Is there an easy way to achieve a cross-browser video player and embed it in a rails app? I tried swfobject 1.5 and 2.2 with jw_player and also flowplayer but ...

How to put capybara output html to a specific folder?

When I use the "Show me the page" step, with Capybara / Cucumber, can I control where the files get output? I can't seem to find the config for this, and my google fu is failing me. Right now it appears that by default they go to the root of my rails folder and clutter up things there. ...

Why does this Ruby statement throw an exception? (Arrays/Bools)

I'm not a Ruby guy, I just play one on television. I have to modify someone's old Cron job to pull down some JSON and convert it into objects. Here's the code raw_json = Net::HTTP.get(URI.parse("url removed to protect the innocent")) tags = ActiveSupport::JSON.decode(raw_json) puts tags.count tags.count will accurately trace as 5, ...

Helper functions in Rails unit tests

I'm using this sort of code in my code in my Unit tests. test "should be awesome" do assert true end I'm using FactoryGirl instead of fixtures. I find that I'm repeating myself a lot and having helper functions would be quite useful. What's the best way to create and call a helper function in the unit test? Is there a before_filt...

Using ruby object in views

Hi, I am trying to display this object in my view --- - !ruby/object:Customer attributes: country: United Kingdom last_name: a first_name: b attributes_cache: {} histories: - !ruby/object:History attributes: start_date: 11/03/2010 finish_date: attributes_cache: {} I t...

MySQL COUNT results getting interpreted in RoR as a string instead of as an integer

Here's my query for the curious. Only the first and last lines should bear on this question: SELECT s.parent_id AS id, COUNT(s.parent_id) as count FROM items i LEFT OUTER JOIN (SELECT item_id, user_id, MAX(created_at) as created_at FROM item_views iv WHERE iv.user_id = ? GROUP BY item_id) AS v ON i.id = v.item_id LEFT ...

Different implementation on ROR

I'm making a very simple website with ROR. class Product < ActiveRecord::Base belongs_to :category has_many :photos has_many :ordered_photos, :class_name => 'Photo', :order => 'name' has_one :random_photo_1, :class_name => 'Photo', :order => '...

How to manage translations as they are added by release?

I work on a RoR website that is translated into a number of languages. It's a real pain to manage the "what's new to translate" for each release. We have to collect all the new keys and send them out in a spreadsheet to the translation team. So, my question is: How do people structure their locales files and manage the addition of new...

Upgrading Ruby broke Rails?

So, I upgraded Ruby to 1.8.7 to make a particular gem work. Hooray, it works now! But...now rails doesn't. I tried reinstalling rails through gem, but that hasn't helped, either. Rake is no longer recognized by my windows box as a valid command, and I can't even start the server without a whole string of errors. My only thought is that...

setting file encodings transferring data via send_data in Rails

Hi, I'd like to transfer a UTF-8 encoded string to the client, rendering the string as a text file (in my case a v-card) using send_data str, :filename => "file.vcf", :type => 'text/html; charset=utf-8' Unfortunately the submitted file doesn't contain any encoding information and address books open the file in the default encoding o...

Appropriate way to handle settings in Rails3 Plugin?

I'm working on a plugin for Rails3. I'd like to allow users to override some settings. At the moment I'm doing this inside my plugin's Rails::Engine class like: config.my_setting = :default_value unless config.respond_to? :my_setting This seems like the wrong way to handle this. Is there a better method or convention most plugins use ...

Delayed Job for ASP.NET to running async code?

Is there a plugin or other to mimic Rails Delayed Job in ASP.NET? What's the best way to run async code or jobs in an ASP.NET application? ...

F-connect all of sudden not working

As of the other day everything was working with Facebook Connect. Now I have to click "Connect" twice for it log me in. ...

Rails — raise ActiveRecord::RecordNotFound (or any 404 status) for invalid date

In my controller controller, I have use Date.new to create a date object to be passed in my ActiveRecord. end_range = Date.new(params[:year].to_i, params[:month].to_i, params[:day].to_i).end_of_day.to_formatted_s(:db) The problem with this above is that if a user tried to change the parameters in the URL manually, such as enteri...

RSpec 1.3 without output

I installed RSpec 2 along RSpec 1.3 and since then I think the spec command runs without executing the test file. I removed RSpec 2 and am using RSpec 1.3 again. I type for example "spec spec/views/messages/show.html.erb_spec.rb" on the commandline and the command returns after a few seconds without output. I added errors to the spec fi...

How to get datepicker in jqGrid search toolbar ?

I want to have datepicker in search text fields and eventually also in edit fields of jqgrid on a Ruby on Rails application. Is there any way ? Has any one used such combination ? Datepicker with jqGrid ? ...

Is Rails appropriate for use with a non-web-centric app?

It seems to me that Rails shines when building web-centric applications such as the Depot online-store app presented in the Agile book or the Basecamp project management system. The crux of these applications is their web interface, and Rails gives you the tools to create these webapps quickly, easily, and elegantly. But what if you ha...