ruby-on-rails

Sending images to RoR app through an API + paperclip

how can I make my rails app to receive images from clients through an API using paperclip plugin. I know how to use paperclip using the ordinary form to upload the images, but i need to send images from a mac client. thanks in advance ...

How to sum effectively

Before I start, I apologize for a bad title but I could not come up with one that describes my question in a satisfying way. If you come up with a better title, I will gladly switch. Suppose I have an Account model and a Transaction model, and I would like to implement a Account#days_since_balance_was_atleast method, taking a sum as its...

Ruby libxml parsing and inserting to database

Hello, I am currently trying to read from an xml file which records the jobs on a PBS. I have succesfullly managed to parse the code, but am unable to insert the objtects into my database, i receive this error: "You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred...

how to identify when a session is created in rails

how to identify when a session is created in rails ...

task :something => :environment

Can someone explain me what happens when I add such dependency to my tasks? Which files are loaded etc.? ...

How can I test one, more or none images in a page with Cucumber?

I want to test if I have 0, 1, 2 or 3 times a pictures ('foo.png') in a certain page with Cucumber. How should I write the custom step? Thanks ...

Passing a variable through AJAX and Rails

I've made an array in my controller with the items that I would like to rotate through. The initial set is used as a partial collection and looped through. render :partial => "partial", :collection => @array[1..4] I also have a link_to_remote link on the page that makes a POST request to the controller to change the range on the colle...

What is the relationship between these two tables in RoR?

I am developing an application like the stackoverflow, which questions or articles have at less one tag. And one tags must have one or more articles. So, I am doing this in migration in RoR. I am consider which relationship is suitable for both table. In article table, should use a "has_many", and in the tag table, should use "has_many...

Rails3 nested-routing issues

I would like to create a mechanism for a User to keep track of other, favorite Users, similar to SO's favorite questions. I'm using the Rails 3.0 beta. To do so, I have a User-Favorite HABTM relationship, which works as expected: class User < ActiveRecord::Base has_and_belongs_to_many :favorites, :class_name => "User", :join_table =...

How to avoid putting the magic encoding comment on top of every UTF-8 file in Ruby 1.9?

I have a Rails project with lots and lots of cyrillic strings in it. It worked fine on Ruby 1.8, but Ruby 1.9 recognizes all source files as US-ASCII-encoded until you provide an # encoding: utf-8 comment on top of each and every source file in the project. Obviously the files don't parse as US-ASCII. Is there a simpler way to say, li...

Recurring Tasks in Delajed Jobs without firing up Rails?

Hi guys, If I need to create recurring tasks in delayed jobs, what is a clean solution? I have an import task that I want to run every 5 minutes, but I don't want to fire up rails/rake in order to tell it to create a Delayed job that can be picked up. If Rails is already running on a system, perhaps I can just create an HTTP request tha...

Ruby on Rails 3 howto make 'OR' condition

I need an SQL statement that check if one condition is satisfied: SELECT * FROM my_table WHERE my_table.x=1 OR my_table.y=1 I want to do this the 'Rails 3' way. I was looking for something like: Account.where(:id => 1).or.where(:id => 2) I know that I can always fallback to sql or a conditions string. However, in my experience this...

match method in routes.rb

I'm trying to follow this tutorial here but the tutorial seems to use this "match" function. match '/about', :to => 'pages#about' Whenever, I do the same, I get this error from the server: undefined method `match' for main:Object How can I edit the routes.rb file such that: it will route from a long file path to a short one ...

create object if object is failed before_save.

Model def before_save self.default_file_name = "#{self.model_name.underscore}.csv" if self.default_file_name.nil? self.default_directory_name = "public/uploads" if self.default_directory_name.nil? verify_methods verify_record end def verify_methods self.errors.add_to_base(_("Invalid row instance method.")) \ if !self.each_r...

Ruby on Rails: Migrations: how do I merge to tables into a new table?

i have two tables attachments: name, doc_name, doc_type, doc_size, cat and media: name, doc_name, doc_type, doc_size, cat how do I write a migration file such that it takes all the entries from both tables and puts them into a new Files table? ...

Making a custom validator with regex..not triggering yet

Hey guys, I thought this would be fairly straightforward, but it's not it seems..maybe I'm just writing the syntax wrong.. In my model I'm checking for certain key words before_validation :deal_validation def deal_validation if self.description.match /(exp\s|expire|ex\s|print|mention|\/)/ errors.add(:description, "Now just a se...

rails - converting an object to an array

Hey, I am trying to convert this object to an array of ints e.g. array(3,4,6) - - !ruby/object:Code attributes: candidate_id: "3" attributes_cache: {} - !ruby/object:Code attributes: candidate_id: "4" attributes_cache: {} - !ruby/object:Code attributes: candidate_id: "6" attributes_cache: {} here is what I tried result ...

ActiveRecord relations when model has both one and many of the same model

My data resembles this: class Team < ActiveRecord::Base has_many :persons has_one :leader end class Person < ActiveRecord::Base belongs_to :team end Person only belongs to one Team, but of the many team members there is only 1 leader. First question: should I use belongs_to instead of has_one in the Team model? Second: Team i...

Ruby on Rails: How do I move all files from one folder to another folder?

But I also need a way to rename them incase there are conflicts. Like if exists? then file.name = "1-"+file.name or something like that ...

Link that performs task and goes to different view

I am trying to perform this task: -click on an image -perform a task in current view/controller (ie NOT in /home) -end up on a different page (view, in this case /home) I have looked at the doc and it's not clear to me how to do this. I'd like to do something like the following (although I know it won't work): link_to image_tag("bu...