ruby-on-rails

Rspec Selenium. Test to check certain Ajax functions passes when i expect it to fail.

I am testing a Ajax action using Rspec and Selenium. My story is as follows: it "should create a new User with any input" do @browser.open "/people" @browser.wait_for_page_to_load "2000" @browser.type "user_name", "Alok Swain" @browser.click "user_submit" @browser.text?("Alok Swain").should be_true end The action i am testing is: ...

Ruby on Rails - Static page as start page

Hello! I am developing an app in RoR which has static and dynamic parts. The static portion is placed in the public/ folder of the app. Now if i have an index.html in my public folder then i will not be able to use the routes configured in my routes.rb The default configurations like map.connect /:controller/:action will not be usable i...

Strengths and Weaknesses - Ruby on Rails

I was wondering what are the strengths and weakness of using Ruby on Rails for Web Application development. I would like an insight from other developers as to why they have chosen to write in Ruby on Rails over other languages and technologies. What does Ruby on Rails provide that has the edge over other web application technologies an...

Rails : fighting long http response times with ajax. Is it a good idea? Please, help with implementation details.

Hi, everybody! I've googled some tutorials, browsed some SO answers, and was unable to find a recipe for my problem. I'm writing a web site which is supposed to display almost realtime stock chart. Data is stored in constantly updating MySQL database, I wrote a find_by_sql query code which fetches all the data I need to get my chart dr...

Rails: link_to_remote prototype helper with :with option

I am trying to grab the current value of a drop down list with Prototype and passing it along using :with like this <%= link_to_remote "today", :update => "choices", :url => { :action => "check_availability" } , :with => "'practitioner='+$F('practitioner')&'clinic='+$F('clinic')&'when=today'", :loading => "spinner.show(); $...

Show a 404 instead of 500 in Rails

In my rails app I have defined the routes so users can access records like http://mydomain.com/qwe2 But if they type a wrong "qwe2" they get a 500 page. I think a 404 would be more appropriate. How can I change the error page that is shown? Thanks ...

Rails routing: optional id for update and destroy actions

In our application we need to have some non standard routes. How can I make router to forward all delete requests to #destroy action even if their is no id parameter in URL? Example: DELETE /users/:user_id/follows/(.:format) {:action=>"destroy", :controller=>"followings"} ...

Ruby on rails authentication guide

Does anyone know of a good guide on building your own authentication system in ruby on rails? I want to roll my own system to use with my community im building :) Thanks! ...

Using regular expressions to remove relative path slashes

Hey Guys I am trying to remove all the relative image path slashes from a chunk of HTML that contains several other elements. For example <img src="../../../../images/upload/1/test.jpg /> would need to become <img src="http://s3.amazonaws.com/website/images/upload/1/test.jpg" /> I was thinking of writing this as a rails helper, a...

How should I define a composite foreign key for domain constraints in the presence of surrogate keys?

I am writing a new app with Rails so I have an id column on every table. What is the best practice for enforcing domain constraints using foreign keys? I'll outline my thoughts and frustration. Here's what I would imagine as "The Rails Way". It's what I started with. Companies: id: integer, serial company_code: char, unique, no...

Can nested attributes be used in combination with inheritance?

I have the following classes: Project Person Person > Developer Person > Manager In the Project model I have added the following statements: has_and_belongs_to_many :people accepts_nested_attributes_for :people And of course the appropriate statements in the class Person. How can I add an Developer to a Project through the nested_a...

How can I change Rails view code for site visitors using SSL?

My Rails app has some pages which are SSL-required and others which are SSL-optional. The optional pages use some assets which are served off-site (images from a vendor) which have both http and https URLs. I need to use https when the page is accessed via SSL to avoid the dreaded "this page contains both secure and insecure elements" wa...

How should I deploy a patch to a Passenger-based production Rails application without downtime?

I have a Passenger-based production Rails application which has thousands of users. Occasionally we need to apply a code patch (we use git) and the current process for doing this (you can assume there are no data migrations) is: Perform git pull origin [production-branch-name] on the server touch tmp/restart.txt to restart Passenger ...

RSpec, stubbing nested resource methods

I've got two models: class Solution < ActiveRecord::Base belongs_to :owner, :class_name => "User", :foreign_key => :user_id end class User < ActiveRecord::Base has_many :solutions end and I nest solutions within users like this: ActionController::Routing::Routes.draw do |map| map.resources :users, :has_many => :solutions end ...

unix at command pass variable to shell script?

Hi, I'm trying to setup a simple timer that gets started from a Rails Application. This timer should wait out its duration and then start a shell script that will start up ./script/runner and complete the initial request. I need script/runner because I need access to ActiveRecord. Here's my test lines in Rails output = `at #{(Time.n...

edit created_at field in rails?

I was wondering if its ok to edit the created_at value of a record in a DB in rails? Best, Elliot ...

Sudo issue with Capistrano - Could not find RubyGem mongrel

I'm having a problem with one of my Capistrano scripts - specifically, using using sudo, setting the path, and finding mongrel_rails. The path is correct, and mongrel_rails is in /opt/rails/gems/1.8/bin, but I getting the following error: /usr/lib/ruby/1.8/rubygems.rb:578:in `report_activate_error': Could not find RubyGem mongrel (>...

Routing problem with calling a new method without an ID

I'm trying to put together a form_tag that edits several Shift objects. I have the form built properly, and it's passing on the correct parameters. I have verified that the parameters work with updating the objects correctly in the console. However, when I click the submit button, I get the error: ActiveRecord::RecordNotFound in Shif...

How do you keep your business rules DRY?

I periodically ponder how to best design an application whose every business rule exists in just a single location. (While I know there is no proverbial “best way” and that designs are situational, people must have a leaning toward one practice or another.) I work for a shop where they prefer to house as much of the business rules as p...

I need to run some code only 40% of the times, how may i do this?

[Rails] I need to run some code only 40% of the times, how may i do this? i need to make some square items, and there can be a max of 5 per row, and a min of 1 per row. then i want to have a row with 2 boxes, 5boxe, 1 box and so on, random... the last box of the row, will have a clear:both class.. ...