ruby-on-rails

If statement with code on same block in haml, RoR

Hello, i have this Haml view: !!! strict %html{:xmlns => "http://www.w3.org/1999/xhtml"} %head %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"} %title Lighty | #{@page_title || "Home"} %body #popup Login here #fade #wrapper #container #header ...

redirecting domain to nameservers in heroku?

I have configured my domain to heroku IPs 75.101.163.44 75.101.145.87 174.129.212.2 But it's not redirecting my app to my domain. The error says There is no app configured at that hostname. Perhaps the app owner has renamed it, or you mistyped the URL. Does each Heroku app have its own IP address? If so how to get the unique IP and ho...

Multiple domains on a single rails app

This is the first time I'm creating an app using Ruby on Rails. I would like to switch the database depending on the site which is loaded. With php I used to do a simple strpos on http host, and set the database name depending on that. How can I do this with rails? ...

How to embed multiple tags in Rails routes, like Stackoverflow.

When one selects a Tag on stackoverflow, it is added to the end of the Url. Add a second Tag and it is add to the end of the Url after the first Tag, with a '+' delimiter. For example, http://stackoverflow.com/questions/tagged/ruby-on-rails+best-practices. How is this implemented? Is this a routing enhancement or some logic contained...

Rails Metaprogramming: How to add instance methods at runtime?

I'm defining my own AR class in Rails that will include dynamically created instance methods for user fields 0-9. The user fields are not stored in the db directly, they'll be serialized together since they'll be used infrequently. Is the following the best way to do this? Alternatives? Where should the start up code for adding the meth...

If I have a Riak DB, should it store to Amazon S3 or to the EC/2 instance?

I am setting up an Amazon EC/2 instance, and am putting Riak on it. I am wondering if I should store the data locally (and not ever delete the instance), or set up Riak to store to S3 and bring up/take down instances as I need? ...

How to test declarative_authorization with rspec

Is there a way to test the declarative_authorization permissions with respect? In the documentation it has some instructions to use test unit, but I can't seem to find a way to use rspec. ...

Rails to_xml override

If you have an array in Rails, to_xml will nest each object under a 'records' tag. Is there a way to override this to name it something else? ...

How do I create a new instance of a different class when saving a model

I have a Class A that when it is instantiated and saved for the first time or modified it will create an instance of Class B and save it also I want them to be in the same transaction and I want it to be handled in the Model not a controller. I know how to do this in a conteoller with the ‘transaction do’ block but how do I do it in t...

how do i load a csv file in rails from a migrate usiing load data local infile ?

Hi All, I have my csv file in my public folder, and i'm trying to load it from a migration, but I get a file not found error using this script : ActiveRecord::Base.connection.execute( "load data local infile '#{RAILS_ROOT}/public/muds_variables.csv' into table muds_variables " + "fields terminated by ',' " + "lines terminated by ...

rails HABTM versus view (formtastic)

I have two models: The model NetworkObject try to describe "hosts". I want to have a rule with source and destination, so i'm trying to use both objects from the same class since it dont makes sense to create two different classes. class NetworkObject < ActiveRecord::Base attr_accessible :ip, :netmask, :name has_many :statements ...

Them old shared server Rails deployment blues...

Hi! Newb RoR developer here, standing at the finish line of my first paying Rails gig. It's been fun, really, and I'm glad to have it over with so I can get on to using what I've learned on the next project. The client already has their site up on a shared server at Network Solutions (go ahead, yuck it up), which professes to offer Ru...

Creating multiple relationships in rails with same datatypes

What I am trying to do is kind of like this: I have datatypes "user" and "article" for instance. I want to have relationships between these two, but in more than one way. So for instance, I'd like to let a user "like" or "bookmark" an article. So I need to have two relations in the database, one for users liking the article, and one fo...

Determining the date in a timezone that is different than Time.zone

My Rails application makes use of Time.zone so that each user can set their own timezone and see timestamps in the correct zone. However, I would like to have some content that is only available for one day, but for that one day to be the same 24 hours for all users. In order to do that, I was going to use if Time.zone.today == Time.zon...

dynamic check_box using field_for in rails

I have a many-to-many relationship with a link box, and I want to pull those models together into one form so I can update from the same page. I'm really struggling with getting the check_box to even show all the elements of my array - I've scoured the net and been working on this literally all day, and I'm finding it difficult to apply ...

Params order in Foo.new(params[:foo]), need one before the other (Rails)

I have a problem which I don't know how to fix. It has to do with the unsorted params hash. I have a object Reservation which has a virtual time= attribute and a virtual eating_session= attribute when I set the time= I also want to validate it via an external server request. I do that with help of the method times() which makes a looku...

Rails 1.0 - Using composed_of gives me a wrong number of arguments (1 for 5) error

I am developing a Rails 1.0 application (I can't upgrade, it's a strange situation) for which I am trying to use the :composed_of functionality. I have a class called StreetAddress: class StreetAddress attr_reader :address, :address2, :city, :state_id, :zip_code def initialize(address, address2, city, state_id, zip_code) @addr...

In Rails, how do I find records by "not equal"

I'm building an application that contains a bunch of projects that are at various stages, and I need to list the completed projects, or the projects that are at various other stages. So to list the completed projects, I name a scope; named_scope :current, :conditions => { :current_stage => "Completed" } and use; @projects = Project.c...

Rails ActiveRecord::MultiparameterAssignmentErrors

I have the following code in my model: attr_accessor :expiry_date validates_presence_of :expiry_date, :on => :create, :message => "can't be blank" and the following in my view: <%= date_select :account, :expiry_date, :discard_day => true, :start_year => Time.now.year, :end_year => Time.now.year + 15, :order => [:month, :year] ...

Rails test db doesn't persist record changes

I've been trying to solve a problem for a few weeks now. I am running rspec tests for my Rails app, and they are working fine except for one error that I can't seem get my head around. I am using MySQL with the InnoDB engine. I have set config.use_transactional_fixtures = true in spec_helper.rb I load my test fixtures manually with th...