ruby-on-rails

How to assign value in a RoR object?

I have a order object, which have a create method like this : def create @order = Order.new(params[:order]) # @order.status_id = "1" respond_to do |format| if @order.save flash[:notice] = 'Order was successfully created.' format.html { redirect_to(@order) } ...

Finding gaps within date-ranges in an associated model | Ruby on Rails

Given the following models: class Room < ActiveRecord::Base has_many :contracts end class Contracts < ActiveRecord::Base # columns # start_date Date # end_date Date belongs_to :room end The contracts of one room are not overlapping. My question is, how i am be able to find gaps between contracts. An Example: room = Room...

Newbie - Rails View Calculation - onchange?

Hi all, I am quite new to Ruby on Rails and what to make sure I set of on the right foot. I want to do some simple "Live Calculations" and am not sure of the best method. If we use the cookbook example. Each Recipe has many ingredients. Each ingredient has a description, qty, cost and a total. What I want to do is the following; 1) i...

How to enable fallback in I18n with globalize2

So that's the problem. In my application globalize2 returns a NIL string if there's no translation on some record, instead of falling back to default_locale. I wonder how to enable thin functionality? Does anyone figured that out? ...

Most Resource-Efficient Way to Deploy Multiple Rails Apps on a Single Server

I have a Virtual Dedicated Server that I use to host small websites that aren't large enough to justify their own dedicated slice. I am a Rails developer and am currently using an Ubuntu/Nginx/Mongrel Cluster/SQLite stack to deploy these applications. I feel that the memory being consumed by each Mongrel instance is too high. I am won...

Is there an open source Ruby on Rails online questionnaire template?

I am relatively new to programming but have some experience with Ruby on Rails and I would like to know if there is an open source template in RoR that I can modify to set up an on-line questionnaire for a charity. It should be able to to collect answers for multiple answer question and yes/no questions, and a some sort of skipping logic...

Ruby on Rails Rspec migrates database when running rake spec:plugins

I'm trying to test a plugin that i wrote by running: rake spec:plugins When i execute this command it appears that it drops my database tables (in my test DB) and then runs a migration without any plugins loaded to give me a clean database. This would normally be fine, but I am using a plugin that allows me to set index length limits ...

need another set of eyes on rails - validation issue

I have a simple form that takes some fields and adds them to the database. Underneath the form is a html table which displays all the products currently in the DB. Controller: pages , action: product #@product is for form capture #@prods is for displaying list of all products def product @product = Product.new(params[:page]) respond...

Error Using Ruby generator in Rails (not Rails::Generator)

Edit: To be clear, I'm trying to use this kind of generator (i.e. with a 'yield' statement) not a Rails generator. I have the following (simplified) initializer mixin in a Rails project that I could use some help with. What I wanted to do was create a generator to track Twitter API calls (this is just for debugging, I know about rate_li...

is Ruby 1.9 compatible with rails 2.3 ?

is possible to use ruby 1.9 with rails 2.3? thanks ...

Active Record Inheritence

Hi all, I have some issues in Rails Active Record Inheritance, I need to create a model that inherits parents class properties(fields) and should also hold its own properties. Ex: Parent Class class Content < ActiveRecord::Base end Classes inheriting parent class (Content) class Wiki < Content // Inherting Class Content end clas...

Rails checkout form with multiple models

I'm creating a shopping cart based on the one in Agile Web Development With Rails (version 3). I have it set up where "items" are added to a "cart", then upon starting the checkout process, they are added to an "order" object as "line_items". "line_items" represent one "item" in any quantity. Up to this point, I'm not deviating from the ...

Using a template to generate json to send to web service

I am generating some json to send to a web service. Currently I am creating a hash, loading it with the data and then calling to_json to generate the json string to send. But I figure it would be much cleaner and more rails like if I could use a template in a .erb file to generate the json for me. All the info I can find on erb files ...

'load_missing_constant': uninitialized constant Encoding (NameError)

I just can't seem to find where the error is or correct it. Everything works well on my Windows env but it's giving me this problem on the linux env. Perhaps it has to do with the different versions but they are the same, 0.9.4 yet I have constantly detected some anomaly when you install Spree in linux. If you type in "gem list" you d...

Ajax error after pagination

I'm using ruby on rails 2.3.2, and I've got a list with checkboxes. So I created a remote_form_for to handle multiple submit buttons. Those operations work great, and so the pagination. The problem raises when I both submit the form and then try to paginate. I get the following error instead of displaying next page, as expected. try { E...

eager loading association on a subclass

I have the following (simplified) class hierarchy: def Parent < ActiveRecord::Base end def Child < Parent belongs_to :other end def Other < ActiveRecord::Base end I want to get all Parent objects and -if they are Child objects- have them eager load the :other association. So I had hoped I could do: Parent.find(:all, :include => [:o...

Paperclip S3 download remote images

How I can download a remote image (http protocol, the url is in the image_remote_url attribute) and save it as an attachment to S3 via Paperclip ? class Product < ActiveRecord::Base require 'open-uri' attr_accessor :image_remote_url has_attached_file :photo, :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml"...

custom error message for valid numericality of in rails

I wanted to have custom error messages for my field names. I stumbled upon another SO question So I added something like this: class Product < ActiveRecord::Base validate do |prod| prod.errors.add_to_base("Product price can't be blank") if prod.prod_price.blank? end end But I also want to check the numericality of prod_price...

What is the difference between rake rails:freeze:gems and rake gems:unpack ?

As far as I know both rails:freeze:gems and rake gems:unpack are placing the gems to /vendor. rails:freeze:gems places them to /vendor/rails, gems:unpack place them to /vendor/gems. The point for me seems to be the same, however. In both cases the goal is to fix the gems and their versions as they were during the development. Is there an...

has_many :through a has_and_belongs_to_many association

I am trying to do the following in a Ruby on Rails project: class FoodItem < ActiveRecord::Base has_and_belongs_to_many :food_categories has_many :places, :through => :food_categories end class FoodCategory < ActiveRecord::Base has_and_belongs_to_many :food_items belongs_to :place end class Place < ActiveRecord::Base has_m...