ruby-on-rails

How to make Rails caches_page survive a capistrano deploy?

Is it possible to configure Rails so caches created with caches_page survive a Capistrano deploy? Ie, can I configure the cache to be saved into a shared directory rather than in the public directory? ...

Working with unsaved associations

Let's say I have two models: class Model1 < ActiveRecord::Base has_many :model2 def save self.attr = <sth. complex involving the associated model2 instances> super end end class Model2 < ActiveRecord::Base belongs_to :model1 end The statement in the overwritten save method will issue a complex query (using find [or a...

Create a flexible, localized, Ruby-on-Rails list-of-values

I have a list of values (Beginner, Intermediate, Advanced, Fluent, Native) that I would like to: act as the model for a SELECT list act as a model to convert ids to values in a HTML table use in multiple controllers and views keep in an order that preserves the business rules (ordered by skill level) localize at some point in the futur...

Ruby on Rails 3 Beta: On ajax get request, I can't respond back with the html.erb view. Is there a work-around?

I have began playing with Rails 3 beta and I am trying to do my usual starter project. I create a simple list of projects, but use ajax requests for the app's navigation. In Rails 3, my usual code does not work for the basic scaffold, I receive an ActionView:MissingTemplate (Missing template projects/new with {:format=>[:js]} Here is...

Stable/repeatable random sort (MySQL, Rails)

I'd like to paginate through a randomly sorted list of ActiveRecord models (rows from MySQL database). However, this randomization needs to persist on a per-session basis, so that other people that visit the website also receive a random, paginate-able list of records. Let's say there are enough entities (tens of thousands) that storin...

How to convert image file to byte array using ruby

hi I need to pass image as byte array to .NET SOAP web service. Can anyone give me example how to convert uploaded image file to byte array using ruby? ...

How to empty/destroy a session in rails?

I can't seem to find it anywhere... How do you delete/destroy/reset user's session in rails? Not just one value but the whole thing. ...

Deep relationships in Rails

I have some projects. Those projects have users through memberships. However, those users belong to companies. Question is, how do I find out which companies can access a project? Ideally I'd be able to do project.users.companies, but that won't work. Is there a nice, pleasant way of doing this? ...

Ruby on Rails testing: How can I test or at the very least see a form_for's error_messages_for?

I'm working on creating a tests, and I can't figure out why the creation of a model from a form_for is failing in the test but works in real browsers. Is there a straightforward way for me to see what the problems are in the model creation? Even better would be, is there a straightforward way for me to test the error outputs that I acc...

Rails remove parent HTML tag

It's pretty easy to sanitize HTML and strip ALL instances of a HTML tag using Rails helpers... But how do you just remove ONE tag? In this case, I'm using a WYSIWYG editor that insists on wrapping all my text in a <p> tag. I want to remove this parent tag without stripping out any other <p> tags within the content of the text. I know I...

Redirect folder to different server

I know you can redirect subdomains to a different server, but can you do the same with folders? Say I have example.com. I can redirect mysubdomain.example.com to a different server, but can I redirect example.com/mysubdomain to a different server? I'd like to host a rails app in that folder on a site that runs php while still maintainin...

Rspec Faker has_one fail in view

I' trying to fix this for hours... I have this on a controller rspec test: it "show action should render show template" do task = Task.make task.mission = Mission.make get :show, :id => task response.should render_template(:show) end But it fails rendering the view because of this: <%=h @task.mission.name %> I ...

Rails deployment from a windows machine

I'm a rails novice and just finished my first rails app(as far as I can tell). Now I'm at the deployment stage and find myself utterly confused--especially because I'm deploying from a windows machine. I bought the pragmatic book on deployment and it seems a little out of date since they're recommending subversion instead of Git. What ...

Is it a good idea to mock/stub in integration tests?

Say there are multiple requests in a integration test, some of them are local sphinx calls(locator for example). Should we just stub out the entire response of these sphinx call, or, since it is a integration test, we want to excise the entire test without stubbing. If that is the case, how do we still keep test independent in the situa...

Conditions with whitespaces in activerecord find

So i am trying to do this Order.find :all, :conditions => "org = 'test org'" what ends up firing is SELECT * FROM `orders` WHERE (org = 'test org') the whitespace in the argument gets stripped. what am i missing.. im really stumped here. please help! ...

Ruby/Rails display general screen when modifications being performed on server

I have a ruby on rails app running a server and sometimes it needs to be taken down for updates/etc. As of now, one way I see to have a general display screen during update periods (when the app is down) is to substitute the files within /srv/www/ directory to just have it display a general screen everywhere that the user could possibly...

for TimeWithZone object, how to change the zone part only?

I have a table Coupon with a field expired_at, which is of datetime type, and before I save the record, I want to change the zone part of the field according to the user's choice. Say, c = Coupon.new c.expired_at = DateTime.now c.expired_at_timezone = "Arizona" c.save! and in the coupon.rb class Coupon << ActiveRecord...

Active Scaffold, problem with search, pagination, sorting

I recently tried to update the active scaffold to the master version under rails 2.3.5, ruby 1.8. I also added :active_scaffold => true, in my routes.rb, for the resource that I needed. The scaffold works in the sense that it displays the first page but other needed functionalities are non-responsive: sorting, search, pagination. I tri...

Rspec > testing database views

How can database views be tested in Rspec? Every scenario is wrapped in a transaction and the data does not look like it is being persisted to the database (MySQL in my case). My view returns with an empty result set because none of the records are being persisted in the transaction. I am validating that the records are not being stor...

Testing a patch to the Rails mysql adapter

I wrote a little monkeypatch to the Rails MySQLAdapter and want to package it up to use it in my other projects. I am trying to write some tests for it but I am still new to testing and I am not sure how to test this. Can someone help get me started? Here is the code I want to test: unless RAILS_ENV == 'production' module ActiveR...