ruby-on-rails

Opening a multipart/form-data ZIP file with rubyzip

I want to extract the files within a ZIP file I uploaded to my Rails app. The files within the ZIP file are going to be stored in the database. I want to open the ZIP file in my action, without first having to save the file to a folder - I want to open the multipart/form-data stream with rubyzip. It looks like rubyzip's ZipFile.open on...

Rails - attr_accessible & mass assignment

I have a question about using attr_accessible in Rails. I sometimes want to set guard_protected_attributes to false in order to bypass mass assignment protection. I'm wondering why the following line doesn't work (it creates the "can't stringify keys" error): @user.attributes=({ :name => "James Bond", :admin => true }, false) ...but ...

Is it true that Jquery + Rails is problematic?

I saw comments in a previous question saying that it is best to use Prototype with Rails. However, my own experience is that Jquery is a superior Javascript library. Being new to Rails, I have not yet investigated how to use Jquery with Rails but I assumed this would work. Is it correct that this may be a problematic combination - especi...

Is it possible to check if a file stream is open in Rails?

I have f = File.new(contacts_file_path, "wb") f.write params[:uploaded_file].read f.close I want begin f = File.new(contacts_file_path, "wb") f.write params[:uploaded_file].read rescue #error ensure if f.open? then f.close end end But f.open? is not a function and I can't find any api documentation. Any ideas? ...

Is there a way to control column order in ActiveRecord migrations?

I'd like to add a column to a table using a migration. Is there a way to add it in a particular position, rather than as the last column? I could find any "order" option in the API docs. ...

Rails Inheritance with relationships problem.

I am using single table inheritance in my project. Instead of explaining more, I'll give the code: # person_profile.rb class PersonProfile < ActiveRecord::Base belongs_to :Person end # company_profile.rb class CompanyProfile < ActiveRecord::Base belongs_to :Company end # person.rb class Person < User has_one :PersonProfile end ...

Calling Super from an Aliased Method

Hello, I am trying to DRY up my code a bit so I am writing a method to defer or delegate certain methods to a different object, but only if it exists. Here is the basic idea: I have Shipment < AbstractShipment which could have a Reroute < AbstractShipment. Either a Shipment or it's Reroute can have a Delivery (or deliveries), but not bo...

Why does rake db:migrate in Rails not add functions to the schema file?

I recently added some SQL functions to my database via a migrate, and they work perfectly fine. Code works, database works, tests don't. The schema.rb file is telling me that it's at the latest version (and it's correct), but it only contains definitions for tables and indexes, not the functions I added. I added the functions via the ...

Do I have to manually uninstall all dependent gems?

I tried to uninstall datamapper using the command gem uninstall dm-core. But it seems that a whole bunch of dependent gems also need to be uninstalled. C:\>gem uninstall dm-core You have requested to uninstall the gem: dm-core-0.9.11 dm-migrations-0.9.11 depends on [dm-core (= 0.9.11)] dm-cli-0.9.11 depends on [dm-core (= 0.9...

Is there a risk of a Ruby gem acting like a trojan?

I was just about to install a Ruby gem by someone I hadn't heard of. But something made me think "Who is this guy?". Is there any risk of a Ruby gem accessing private data on your machine and transmitting it elsewhere - since the gem system has Internet access? Or are there protections against this? ...

Rails Associations - Cascading Update

I have multiple classes with many associations linking them together and I would like to be able to take the top-level object, close it, and have all of the child-objects closed as well. I need each object to be closed because I want to be able to pick any parent and have all of it's children closed. For example (I realize this probably...

Rails datepicker help

I'm trying to use the calendar_date_select plug-in in my rails app and am 80% of the way there. I've got this in one of my views: <%= calendar_date_select_tag "calendar", "", :embedded => true, :year_range => 10.years.ago..0.years.ago %> The calendar shows up just fine, but I can't figure out how to get the value of the sele...

Rails polymorphic many to many association

I'm trying setup a generic sort of web of related objects. Let say I have 4 models. Book Movie Tag Category I would like to able to do: book = Book.find(1) book.relations << Tag.find(2) book.relations << Category.find(3) book.relations #=> [Tag#2, Category#3] movie = Movie.find(4) movie.relations << book movie.relations << Tag.fin...

Action-specific exception handler HTML in Rails

I've got a bunch of XHR actions in a controller, which return some HTML to insert into the page. If the response is an error, then it puts the output into a special error div. So far, nothing particularly interesting. However, this general process doesn't work for Rails' exception handling. If I raise an exception in my XHR actions, ...

Where to handle a restore action in a REST MVC application?

After destroying a resource in my Rails application, the user can restore it clicking on a link. Currently this restore action is routed to the destroy method of the corresponding resource controller. When this method finds the resource in the database, it destroys it and moves the record in a trash table. When it does not find the re...

gemsonrails failing with

Environment: Ubuntu. I have followed the instructions thusly: $ sudo gem install gemsonrails This runs successfully. It fails on this step: $ cd rails_app_folder $ gemsonrails This fails because gemsonrails is not on the path. However runnings gemsonrails like so: /blahblah/gemsonrails Yields the following error message: ...

Elegant method to test validates_associated in Rails Unit Tests?

Seems like this should be findable with a couple of Google searches...but no luck. I'm looking for an elegant approach to testing validates_associated in my models, such as... class Network < ActiveRecord::Base ... validates_associated :transporter ... end And the test: class NetworkTest < ActiveSupport::TestCase test 'should no...

Storing documents using Ruby On Rails

I would like users of my ruby on rails app to be able to upload documents (Word Documents, Spreadsheets, PDFs, etc). What is the best way of doing this? ...

Recommended Carts for Rails e-commerce app.

All, I'm building a Rails app, using Active Merchant to interface to PayPal website pro. I'm wondering if I should develop the cart myself, or if there is a good off-the-shelf cart that people can recommend. Googling reveals a few options such as http://www.ecompages.com/ .. too young?, substruct (http://code.google.com/p/substruct/) ...

Serving Large Files Through Nginx via Rails 2.3 Using x-sendfile

Let's say I have a Rails 2.3.2 application fronted by nginx and served by mongrel in which I need to serve a large static file through Rails (to control access to it). I want the Rails app to delegate the transfer of the file to nginx, to avoid blocking the mongrel instance. The available information seems contradictory and incomplete. ...