ruby-on-rails

Is it possible to put just a rails form element in a partial?

My app has a select box for users to choose a "venue". This select box is, as you would expect, in a form. I also have an action somewhere on the page that creates a new venue via AJAX. After the new venue is created, I would like to updated the venue select box to reflect this. My solution was to put the select box in a partial and ...

unable to save a model from rake task

Hi, I am writting a rake task that would connect to a legacy ORACLE database, get some 'issues' records from a helpdesk application, apply some transformation and store it in another database (Redmine). The problem is that even though the script runs smoothly on Windows, it fails to run on RHEL 5. The library files are all installed ...

How to restart Rails from within Rails?

Ok, so I would like to create an action in Rails to restart itself. I did a little searching and found: http://snippets.dzone.com/posts/show/5002 Which suggests 2 commands, one to stop and another to restart. The following kills: ps -a|grep "/usr/local/bin/ruby script/server"|grep -v "grep /usr"|cut -d " " -f1|xargs -n 1 kill -KILL ...

How can I determine if my ActiveRecord object violates a unique database key/index?

ActiveRecord's validates_uniqueness_of is vulnerable to race conditions. To really ensure uniqueness requires additional safeguards. One suggestion from the ActiveRecord RDocs is to create a unique index on the database, for example by including in your migrations: add_index :recipes, :name, :unique => true This will ensure at the d...

What exactly is Rake ?

Dear all In simple terms, what does Rake do? What purposes does it have? I understand it's a build tool but I'm looking a bit more detail. (For a simpleton.) Many thanks Skipz ...

Rails: Model method execution sequence

I have problem in my model. I want method to use another property of model but before using it I want another method to be executed (to make property have value). Here is an example: def medthod_one=(val) self.value = val end def method_two self.second_value = self.value / 2 #just for example end So, in my case self.second_...

When creating an object in Ruby on Rails, which method of saving do you prefer, and why?

When writing the "create" method for an object in a Ruby on Rails app, I have used two methods. I would like to use one method for the sake of cleaner and more consistent code. I will list the two methods below. Does anyone know if one is better than the other? If so, why? Method 1: def create1 # is this unsecure? should we grab ...

Rails flash messages in Java

What's the best way to achieve Rails-like flash messages such as "Update successful" http://api.rubyonrails.org/classes/ActionController/Flash.html) in the Java world? I'm using Spring MVC. ...

Installing hpricot for JRuby

I'm trying to look at cucumber for Jruby on Rails. One of the pre-requesites is webrat which has as pre-requisite hpricot. I've installed the gem with hpricot using: gem install hpricot --source http://code.whytheluckystiff.net --version 0.6.1 --platform java This installs the java version of hpricot. I add the hpricot_scan.jar to the...

How to give an order a shipping address and a billing address in rails

In my online store, each order is associated with a shipping address and a billing address (they can be the same, of course). This is my first attempt to model this: Class Order belongs_to :billing_address, :class => "Address" belongs_to :shipping_address, :class => "Address" This works pretty well, but now the form helpers don't ...

Unobtrusive jQuery autocomplete in Rails

I'm using rails, but doing all my Javascript unobtrusively using jQuery in application.js. Unfortunately, this makes it quite difficult to reference URLs. For example, if I want to give a field autocomplete behavior, I have to hard-code the autocomplete URL in application.js since the rails url_for isn't available. Is it possible to ma...

Rails Partial rendering results in a blank page?

I'm stuck with a bug at the moment which is puzzling me. I have a layout containing some HTML and a partial (for the navigation) - there is nothing else there other than the yield. If the nav is included as a partial I get nothing returned to the browser at all (blank page) but everything else appears normal If I remove the partial th...

How to freeze rake?

I have a rails-app (2.3.2) that I need to install on a server on which rake isn't installed, and on which I haven't got privileges to install gems, so I'd like to freeze the rails gem. However, I can't figure out how to do that. I've put it in the dependencies in environment.rb, but "rake gems:unpack GEM=rake" has no effect. "rake gems"...

Nested Object w/ Checkboxes - mass-assignment even with accepts_nested_attributes_for ?

I thought that there should have been a simple solution to this, given that Rails 2.3 has this newfangled nested forms feature. Basically I want to create or update a user and assign them roles at the same time. It seems like I'm doing everything right but I get the error WARNING: Can't mass-assign these protected attributes: roles_attr...

Rails : uninitialized constant error on Active Record destroy

Hello I am having an issue when trying to destroy an active record instance. It involves the following AR class Client < ActiveRecord::Base has_many :phone_numbers, :dependent => :destroy has_many :email_addresses, :dependent => :destroy has_many :user_clients , :dependent => :destroy has_many :users, :through => :user...

Autotest inifinitely looping

I've run into a problem using autotest with a Rails project, that when a test fails (ie, I modified a test file and autotest automatically runs the test), autotest continously tries to run the test (failing each time of course since the file hasn't yet been modified), instead of waiting until the file is saved again. And with growl notif...

Why did post fail in my Rails functional test?

When I run a post in my Rails functional test setup do post :create, :user => Factory.attributes_for(:user) end and it fails, I don't get any feedback as to why. I know that it fails because my assertion to make sure that there's one additional record in the database fails. I tried to do setup do post :create, :user => Factory....

How do I use a Rails ActiveRecord migration to insert a primary key into a MySQL database?

I need to create an AR migration for a table of image files. The images are being checked into the source tree, and should act like attachment_fu files. That being the case, I'm creating a hierarchy for them under /public/system. Because of the way attachment_fu generates links, I need to use the directory naming convention to insert ...

What's an example of Java functionality that I could add to a JRuby/Rails project?

This is actually two questions rolled into one. Is there a particular type of Java functionality that people are using JRuby for or is it mainly because of the performance advantage that JRuby gives versus the MRI? The reason I ask is, I'd like to add some Java functionality to a Rails project (just to show that it's possible). Idea...

Undefined method in my app. What's wrong?

Hi there! I try blocking Ip addresses in my app like this - lifeonrails.org. I already have a module in /lib and model banned_ip. Why I have this error below from views/banned_ips/index.html? ===My error:=== NoMethodError in Admin/banned_ips#index *Showing app/views/admin/banned_ips/index.html.erb where line #9 raised:* undefined me...