ruby-on-rails

In RAILS3 - When Creating a Record with 3 columns - how to only accept if all 3 are populated?

Hi. I have a model in Rails 3. When creating the record, there are a total of 3 columns for the model. Right now, Rails allows for creating a record if only 2 of the 3 records are populated? In rails, how do you tell Rails only create a record if 3 values for each column exist when creating? thank you ...

How to create different development and production configurations for devise gem in rails 3

How to create different development and production configurations for devise gem in rails 3? ...

[rails ]link created by eRB have the same ?number every time i refresh

such as <img alt="Auto" class="list-image" src="/images/auto.jpg?1287492558" /> the ?1287492558 and with it i cant load the thing with question marks and numbers. And i can load it as soon as i deleted the thing. So as the style sheet that i load dynamically using eRB. I also discover that i would able to load the image for the ...

Rails 3 - AJAX, response JS - How to Handle Errors

Given the following controller: def create if @mymodel.save format.js else format.js { render :js => @mymodel.errors } end end What's the Rails way of handling a .JS error response... Do I create .js file with a different file name just for servering Errors? Do I add an IF ELSE in the .js file? t...

Clone an object in rails for use in forms

Hi, I have a model (Person) and an instance of this model (my_person). Now, I want to make it possible to create a new Person based on my_person. So there is a clone link, that should redirect to a form, that is prefilled with the data of my_person. That's no problem, I used new_person = my_person.clone My quesion is now: The form con...

Starting a new project - should I go with Rails 3 or 2.3.8?

I'm starting a new rails project and after a conversation with the customer, they said they preferred to go with Rails 2.3.8 since it has its reputation, all the gems and plugins work well with it so eventually, choosing rails 2.3.8 now will lead to less problems during the development process. In addition, they say that after the projec...

How do I add domains to Heroku app using Ruby code?

I'm creating an app that allows users to use their own domain. What method do I use in my Rails app to automatically register their chosen domain with Heroku? I'll also need to deregister it if they change it. ...

I am new on rails.Please post the suitable example

How to do Unit Testing in case of Association ?? Please post the suitable example. ...

Ignore validation failure when using accepts_nested_attributes_for (i.e. prevent rollback)?

So suppose I have the Person and Child models: class Person < ActiveRecord::Base has_many :children accepts_nested_attributes_for :children end class Child < ActiveRecord::Base belongs_to :parent, :class_name => "Person" validates_presence_of :name end Now when I use a nested form and save a Person with 2 new children...

Ruby on Rails: I installed the native pg gem on Mac OS Snow Leopard 10.6.3, but I still get an error "no such file to load -- pg"

I'm using Rails 3.0.1. I installed the native pg gem for postgresql with this command: $ export ARCHFLAGS='-arch i386' $ sudo gem install pg -- --with-pg-config=/Library/PostgreSQL/8.4/bin/pg_config When I run the gem list, I can see that pg 0.9 is installed. However when I set the postgres database adaptor and re-run the server...

Number to English Word Conversion Rails

Hi, Anybody knows the method to convert the numericals to english number words in rails? I found some Ruby scripts to convert numbericals to english words for corresponding words. Instead of writing a script in ruby, i feel that direct function is available. Eg. 1 -> One, 2 -> Two. ...

How to integrate Carrier site using rails application

Hi All, I am integrating the UPS, USPS, DHL and FEDEX with my rails application. For that i am using 'trackify' plugin to find the carrier type for given Tracking Number and for also finding the XML response from the respective tracking site. I want complete guide for each of the above about How to Integrate Tracking API's? ...

attachment_fu testing in rails 3

I am trying to write specs for a working file upload functionality using attachment_fu. However, the sample code given by the author for testing requires me to require action_controller/test_process so that I have access to ActionController::UploadedStringIO class. I have used this before in rails 2.x but for rails 3, it fails to locate ...

Setup Devise to only allow editing of own records?

I've got Devise working in my Rails app but I can't figure out how to now lock it down so a user can only edit their own record in the users table AND in tables belonging to the user. What am I missing here? Is this done in the controller or the model? ...

Is it possible to use a class method to define a CSS style?

I am trying to build in color-coding in my site for a particular class method, such that some values display in a different color if they are low. I just defined a class method that translates numbers stored in my database to words that are displayed to my users. # model.rb def numbers_explained numbers_explained = case number wh...

Configure dynamic assets_host in Rails 3

I want Rails 3 to dynamically grab assets depending on current domain: mysite.com - assets.mysite.com mysite.ru - assets.mysite.ru Is it possible out of the box? Or I should implement it manually? ...

Amazon S3 direct upload not recognizing file's content type

I have my Rails application set up where each user can upload an avatar. The image is uploaded directly to Amazon's S3 using HTTP Post. So far everything is working except that the user is able to upload any type of file. I'm using a fork of the d2s3 plugin by camelpunch. Here are the helpers: policy = Base64.encode64( "{'expirat...

How to generate a Javascript AJAX POST method and handle it in Ruby on Rails 3.0

I want to do something quite simple. Click a button on my html javascript page which sends a bunch of data to the server using the AJAX Post method. The server uses the data sent by the POST method to generate an xml file which it then sends back to the user so they can save it. My knowledge of ruby on rails is very limited and I've loo...

Rails transaction: does it matter on which ActiveRecord model class?

When I have 2 objects to save inside a transaction a = A.new(...) b = B.new(...) Does it matter on which model class I invoke the transaction method? A.transaction do a.save b.save end or B.transaction do a.save b.save end IMNO both use the same db transaction, because ActiveRecord can only handle one connection, thu...

Prawn - how to generalize the common things in the pdf document into a separate module for code re-usage?

I am using the Rails Prawn to generate pdf files. Now that i am able to generate pdf with all necessary things that i need(eg. table, header, footer, logo, borders etc...). Now I need to use the common things(header, foooter, borders) in a method inside separate module and call this method from my original program? My original program:...