ruby-on-rails

How to remove a URL's trailing slash in a Rails app? (in a SEO view)

In order to avoid content duplication, I would like to avoid the pages of my site being accessible by several URLs (with or without trailing slash). Currently, the URLs catalog/product/1 and catalog/product/1/ lead to the same page. My goal is that the second URL redirect to the first (redirection 301, of course). None page of my...

Web framework maintainability

Hopefully the last question in choosing an implementation language for this web app, but before pitching to anyone, we would like to know what your experiences are with maintaining an application. We maintained (and since moved to a hosted solution) a web portal based on Perl. The problem was that we had cases where Perl was updated o...

Are Rails Engines appropriate for managing multiple versions of an app?

I have a rails app with core features (layout, users, messaging etc) and 3 different versions that add their own unique features on top of the core set. Each of them are currently in separate directories and deployed separately at the moment. When I make a change to the core features, I have to copy them by hand at the moment into each ...

Rails Application Controller for critique (feel free to be harsh)

Hi All, I've written an application controller that handles 99% of what I need any controller to do. I've posted it here (pastebin). Like I said, feel free to be harsh. -update: added comments :) Thx, -C P.S. I would like to say that my intention here is to overwrite methods that need different functionality in sub-classed contro...

rails : what's wrong with this multiple join with conditions on the associations?

Here are my models: class Deck < ActiveRecord::Base belongs_to :game has_many :deck_cards end class DeckCard < ActiveRecord::Base belongs_to :card belongs_to :deck end class Card < ActiveRecord::Base end Here's my attempted find: DeckCard.all :joins => [:card, :deck], :conditions => {{:decks => {:game_id => @game.id}}, {:ca...

Rails Web Service SOAP Client

Hello I am getting an error when trying to access a web service via soap soap_client = SOAP::WSDLDriverFactory.new("http://api.upsidewireless.com/soap/Authentication.asmx?WSDL") driver = soap_client.createDriver @p = driver.GetParameters(:username => 'uname', :password => 'pword') #ERROR => wrong number of arguments (1 for 2) I can c...

How do I include a module to a class such that the module overrides the class?

Is there a way to include a module to a class such that the module's methods override the methods of the class? For example: module UpcasedName def name @name.upcase end end class User attr_accessor :name include UpcasedName end u = User.new u.name = 'john' puts u.name # outputs 'john', not 'JOHN' In the example above, u...

Prototype/Scriptaculous: Selecting groups of paragraphs (<p>) by clicking on them.

A list of paragraphs (<p>) is given. As soon as the user clicks on paragraph A the class of paragraph A changes to "activated". Now the user selects paragraph B and all the paragraphs between A and B change their class to "activated". By clicking on B again, only A remains with the class "active". By clicking on A the class "active" ...

How can i use attribute_fu and treat the first element differently?

I am using attribute_fu with rails 2.2 and I would like to treat the first nested element differently than the rest, meaning I would like to render a different partial or pass a parameter to the existing partial. Is that possible ? Thanks, Cezar ...

Ruby: Posting XML to RESTFUL Web Service using Net::HTTP::Post

I am having trouble getting this to work so any help would be appreciated! Basically, the request.body contains valid XML for the Web Service like so: <somedata> <name>Test Name 1</name> <description>Some data for Unit testing</description> </somedata> ...but the service returns empty XML, like so (note that the id field is returned s...

searching and deleting in activerecord array

Hi all, Groups has_ many users. I have 2 activerecord arrays: 1. groups = containing groups with its users. 2. users = containing users attending an event. I start by iterating over the groups. Then I iterate over the users in the second array and search for that user in the first array (see code). If the user is found, show an...

RJS: Check for existing page element?

I have a textfield with the id "foo" that sometimes exists and sometimes not. If it exists I'd like to fill in a certain value. How do you do this by using RJS (in Rails 2.2)? I tried this and it doesn't work: if page[:foo] page[:foo].value = "bar" end I get TypeError: Null Value if the textfield doesn't exist. ...

Howto provide software drops via SVN?

Delivering software should be fast and easy. Otherwise it's annoying to spend time in building packages manually. So I would like to use SVN to ship my rails project to a productive environment. The idea is that operational guys just have to checkout the inital project by executing: svn co https://my-server/vs/my-project/tags/1.0.0 A...

what are some good ways to populate a rails development database with fake data

I am moving away from fixtures and populate and looking for some alternative tools to populate my development database with fake data. Any thoughts? ...

With ActiveRecord has_many through relationships how do I delete associations while keeping objects

In Rails how do you delete a has-many through association while retaining the formerly associated objects? Is there an ActiveRecord way to do this or I do need to write the SQL? Also is it possible for the objects to remain friends once the relationship is gone? [ <-- lame joke attempt] ...

Only delete from memory not from database

Hi all, I have an ActiveRecord array containing a list of shops. shops = Shop.find(:all) I want to delete a record from shops without deleteting it from the database. shops.delete(a_shop) wuold result in a delete sql querry. I just want the shop to be deleted from the activerecord array but not the database. Can this be done? T...

Rails: Unable to access log file

I get the following error when restarting my rails app. I've had this problem before, on another server with another app, but can't remember what the problem was, or how I solved it. Rails Error: Unable to access log file. Please ensure that /apps/staging/releases/20090310162127/log/staging.log exists and is chmod 0666. The log level ha...

How can I avoid running ActiveRecord callbacks?

I have some models that have after_save callbacks. Usually that's fine, but in some situations, like when creating development data, I want to save the models without having the callbacks run. Is there a simple way to do that? Something akin to... Person#save( :run_callbacks => false ) or Person#save_without_callbacks I looked in t...

Problem with adding custom sql to finder condition

I am trying to add the following custom sql to a finder condition and there is something not quite right.. I am not an sql expert but had this worked out with a friend who is..(yet they are not familiar with rubyonrails or activerecord or finder) status_search = "select p.* from policies p where exists ...

Ruby on Rails calculating "rank" based upon database values?

Is there an easy and fast way to calculate the rank of a field in a database using Ruby on Rails? For example, if I have a math_scores table, and would like to find a given a MathScore.find(:all, :condtions => ... :order =>...) then iterate through all of them to find out where the test score falls, but there's got to be a more straight...