ruby-on-rails

What attributes are updated in model

Hi all, Is there a way I can know what attributes are updated in my model? I only want to do a validation on a user when a certain attribute was posted. This would actually be the hash that is sent via the params eg: @user.update_attributes(params[:user]) Thanks. ...

Why doesn't RoR take advantage of native extensions/code inlining techniques?

Those outside of the ruby community (and some inside) oft reference ruby applications as being slow. For many of us this is an irrelevance, IO bound operations etc. However, when it does become a problem there is little to hold us back from taking advantage of native code to speed things up. To this end I am wondering why RoR (itself the...

update the div in the loop object variable

I have one page in view side of my application where there is a loop of the object @users now i want to update only one part of the div and that div is inside the loop i have made div dinamic but i want to update that div , in the same page. I have used partial page to update the page by controller , but that is not wrking due to div is ...

Two columns must not equal each other in Rails

I'm creating a social network in Rails and I have a model like this: create_table "friendships", :force => true do |t| t.integer "user1_id" t.integer "user2_id" t.boolean "hasaccepted" t.datetime "created_at" t.datetime "updated_at" end The problem is that you cannot add yourself as friend, so I tried this in my...

Rails - Create/Destroy record in join table

I'm working on this record insert/delete I'm not sure what the syntax is to perform the query. I have a user model and an event model. I have created a joining table called Personal that stores the user_id, and event_id of any events that the users like. I created an "Add" method in my events controller so whenever someone clicks it r...

How to begin learning CakePHP or any other MVC framework

I want to learn some MVC framework. I am trying to learn CakePHP by reading the docs on their website. But I am finding it very difficult to learn it. Can someone suggest a good way to begin learning CakePHP and provide some alternative websites? ...

Is there a rails3-compatible emacs mode yet ?

Rinari hasn't been updated in the last few months, and there doesn't seem to be such progress made in the branches on github. I've never tried emacs-rails, but from what I can see, the same applies. So, is there a rails mode somewhere that's compatible with v3 ? ...

[Rails] counter_cache is stale in after_create hook

I rely on a counter cache value in an after_create hook of my model. However, my hook is called before the counter cache gets updated, thus breaking a computation. Is there any way to force a counter cache "flush" so that I always see an up-to-date value in after_create? ...

Cucumber+Capybara: Problem with a scenario that redirects the browser outside of my app

Given I have a rails app And I'm using cucumber And I'm using capybara And I have an action that results in a redirect_to "http://some.other.domain.com/some_path" When I test this action Then the in-app portion of the test works fine But I see this error: No route matches "/some_path" with {:method=>:get} (ActionController::RoutingError)...

How would you represent the following data set on the Model layer in an MVC application?

Foreign Direct Investment (% GDP) 2000 2001 2002 2003 2004 2005 2006 Brazil 5.09 4.05 3.28 1.84 2.74 1.7 1.73 China 3.22 3.36 3.39 2.86 2.84 3.44 2.81 India 0.78 1.15 1.11 0.73 0.83 0.94 2.13 Mexico 2.87 4....

find(:all) and then add data from another table to the object

I have two tables: create_table "friendships", :force => true do |t| t.integer "user1_id" t.integer "user2_id" t.boolean "hasaccepted" t.datetime "created_at" t.datetime "updated_at" end and create_table "users", :force => true do |t| t.string "email" t.string "password" t.string "phone" t...

Rails: How do I add an additional parameter to resource-based link_to call?

I have a resource defined in routes.rb like so: map.resources :users I like using the cleanest link_to option, which would be: link_to @user I'd like to add an additional parameter to this call, though: "view=local" If I were using the user_path, I'd do this: link_to user_path(@user, { :view => 'local' }) Is there a way to get ...

How to automatically merge modifications in multiple projects ?

Hi, I'm working on a Ruby on Rails (3 beta) project which is basically a simple back-office with users, contents and localizations. This back-office will be our start for all news projects. However this base isn't perfect and might be widely improved. So i would like to keep improving this base during the development of the new proje...

Passenger 2.2.9 Ruby EE Ubuntu.. Can't get it to use 'default' production environment

Using Apache2 (2.2.12) / Passenger (2.2.9).. Have 2 apps running.. One runs fine in production mode the other insists on being in development mode. Have booted mongrel into production mode and the app works fine.. (script/server -e production) Tried the following with no result... Forced the RailsEnv in the apache virtual host. For...

Retrieve all association's attributes of an AR model?

Hello, How do you think is the more optimum way to retrieve all the attributes for each association that an AR model has? i.e: let's say we have the model Target. class Target < ActiveRecord::Base has_many :countries has_many :cities has_many :towns has_many :colleges has_many :tags accepts_nested_attributes_for :countries...

First time rails install, help with gems/rake

Hello all, I just did a first time ruby enterprise edition, installed some gems, and now I'm trying to do a ' sudo ./rake gems:install' and getting a: rake aborted! No Rakefile found error. Firstly, what directory should I be doing this from? Here are the steps I've followed: download ruby enterprise from http://www.rubyenter...

Where to put partial specific javascript in rails 2.x

Consider the following partial, it gets inserted into a page if someone clicks ajax "add comment" link. The question I have is: Is this the best place to include that javascript? I thought it was best to put it in the application.js, but because the partial gets added via ajax, the validate method called within $(document).ready block ...

Rails DB seed with yml files sometimes removes and re-adds existing records, sometimes not. What gives?

I have a rails project with seeds that are executed using rake db:seed. This in turn loads the RB files in the db/seeds directory which in turn executes something like this: Fixtures.create_fixtures("db/seeds","projects") There is a projects.yml in the form project_name1: property: value project_name2: property: value In the ...

Modeling relationships between spots and checkins ala Foursquare

Here's the scoop: As a learning exercise, I'm trying to write a Rails clone of one of the many location-based games out there (Foursquare, Gowalla, etc.) I have Users who create and check in to Stores. In ActiveRecord terms: :user has_many :stores :store belongs_to :user But now I've created a third model - Checkins. The table behin...

Keep search text through session

I'm working on Ruby on rails 2.3.2 and I'd like to keep the search text through postback so I can populate it after that. Right now, the search page is called by a method called "search" on a controller. Once the search is done I render the file this way: render :file => '/search/index', :layout => true, :use_full_path => true I'd li...