ruby-on-rails

In Ruby on Rails, why does a script match /something([^<]+)/ perfectly, but match the </td> also when it is the "script/runner" mode?

I tried a simple script with arr = data.scan /<td>([^<]+)/ and the arr is filled with the data within the <td> and </td> when it is run using ruby try.rb but when it is run using ruby script/runner app/try.rb so that it is run just like inside of script/console, then now there is an extra </td> attached to the matched data... ...

Heroku - DelayedJob & Autoscale

Hi I'm pretty much in wonder of the idea of autoscaling workers on Heroku with this delayed job branch. Only problem is I can't figure out why it won't work. What I've got thus far: I've installed the branch as a plugin. Added the two lines of configuration as described in the branch comments: Delayed::Job.destroy_failed_jobs = fals...

Rails for Java Desktop MVC

I'm looking for a desktop application framework similar to Rails/Django but for Java desktop GUI's: Good ORM (xml, db, whatever) MVC Default directory structure View Helpers / CRUD support Open Source & Mature Basically, I want to define a large number of models for a desktop application either in Java or schemas and have a simplist...

Custom method redirect in Rails

Hi, I've created a custom method in my model, which finds a record by name: def find_city Place.find_by_name(city_name) end I can call this method in my view with place_path(@place.find_city), which works great when a place with the appropriate name exists. What I would like to be able to do is write in a redirect for when the plac...

In Ruby on Rails, "if defined? Product" doesn't work in script/runner mode?

If there is a simple script and to distinguish whether it is running by itself or being run inside the Rails app environment, I tried using if defined? Product # something end but it failed to be recognized even though Product is defined and can be used otherwise. Since then I tried using if defined? RAILS_ENV instead and it wor...

What are the advantages of doing unit testing over plain "assertions" ?

I am currently building an application with one of the models being fairly complex. I am currently using assertions raise "error message" if "settings failed" question is - what are the advantages of using the Unit:testing frameworks over these assertions? ...

how to manage 3 many-to-many models in Rails

I'm following Railscast Advice of making a different model to maintain many-to-many relationships. However, I am having trouble extracting transitive relation data. Imagine that there are 3 models with many-to-many: User <-> Color <-> Shades I've made 2 more models: ColorLiking (maintains User <-> Color), DiffShades (maintains Col...

In Rails, how can one move a "new" view for one model to a "show" view from another model?

I've been reading and watching videos on nested forms, but I haven't had any luck getting things working. (...and I know this just has to be incredibly easy...) I have this view 'views/comments/new': <% form_for([@job, @comment]) do |f| %> <%= f.error_messages %> <p> <%= f.label :body %><br /> <%= f.text_area :body %> </p> <p> <%= f.su...

Restricting file access on server with Rails Nginx and passenger

I have a Rails application (with Nginx and Passenger) that save video files on the server. How can I restrict access to those files to logged in users with permissions to those files? I believe when I try to access a file such as www.mysite.com/videos/video1.flv it bypasses Rails correct? So Do I have to do something at Nginx level to re...

Assigning Environment Variables in Ruby on Rails

I have a program that makes calls to an internal web API. However when we're doing development work on the sites we don't want the program to call our production web API but the staging version of the Web API. What's the best way to do this in rails? I feel I should be assigning some sort of variable in development.rb and one in produ...

Parsing a JSON POST request to a object?

Hi I am quite new to rails. I have this code in my controller: @schedules = Schedules.find(:all, :conditions => ["id = ?", params[:id]]) respond_to do |format| format.html # list.html.erb format.json { render :json => @schedules.to_json } end This works super, but how do I get the other way? How do I parse the received JSON to a ...

How to compare a string to dates in a find clause ?

Hi, I want to get models whom date is within a date range. So I want to do something like MyModel.find_all_by_field1_id_and_field2_id(value1, value2, :conditions => { :date => nb_days_ago..Date.yesterday }) The thing is, the date attribute of my model is a string (with the format "08-24-2010"), and I can't modify this. So to compare i...

Rails 3 ActiveModel::Serializers seem to need lots of support methods

I'm returning to RoR after not using it for a few years and I'm trying to use ActiveModel to serialise a plain object to XML. I'm doing the following, as per the comments in activemodel/lib/activemodel/serialization.rb: class XmlError include ActiveModel::Serializers::Xml attr_accessor :code attr_accessor :description def at...

Read domain's cookie from subdomain with Rails

Hi, In order to store some Google Analytics data, I would like to access to GA "__utmz" domain's cookie (domain=.example.com) from my www subdomain (domain=www.example.com). Is it possible to read this domain's cookie from a subdomain ? If yes, how can I do that with Rails ? cookies[:__utmz] doesn't seem to work with all browsers. I k...

javascript scoping issue inside a function call

I'm having a really hard time figuring out the scoping issue with the following script using the Google Maps API v3. I'm trying to geocode an unknown number of records (pulled from a database) and create a PolyLine from the results. There's some ruby sprinkled in the code, but it shouldn't be relevant to the JS right? var trippath = n...

How do EventMachine & Rails integrate?

I've found plenty of articles showing me what EventMachine is and how to set up endless "Hello World!" examples, but I'm still at a loss as to how this integrates with my Rails application. As a example, I have an existing Rails app that has many concurrent users who may be editing the same row in my database simultaneously. I was think...

Rails - Dynamically defining instance methods in a model

I'm not sure if this can even be achieved, but here goes... :) Lets assume two models, a Page model and a Field model. A Page has_many :fields and the Field model has two attributes: :name, :value What I want to achieve is in the Page model to dynamically define instance methods for each Field#name returning the Field#value. So if my ...

How do you use Ruby on Rails for science (if applicable)?

We do research in systems biology. We prefer to use existing data sets, because collecting new biological data is expensive. Thus, a lot of the scripts we write are little more than transformations of one data set into another. Eventually, we put our results online -- and more and more journals are requiring this sort of thing. So it w...

Hierarchic MVC in Rails 3?

I've read about HMVC (Hierarchic Model View Controller) and it's flexible structure. Have a look at this picture: http://techportal.ibuildings.com/wp-content/uploads/2010/02/MVC-HMVC.png I wonder if the Rails 3 plugins are the answer to HMVC in Rails 3? EDIT: Why cant I start a bounty on this one? No bounty button, bug? ...

How can I find records from today, yesterday and so on with Ruby on Rails?

Hi, I want to find all records, say Posts, created today with Ruby on Rails, then all Posts created yesterday, and so on… how should I do? Thank you, Kevin ...