ruby-on-rails

Rails with ActiveScaffold and Lockdown plugins

Our application is developed using Rails 2.3.5 along with ActiveScaffold. ActiveScaffold adds quite a bit of magic at run time just by declaring as following in a controller: class SomeController < ApplicationController active_scaffold :model end Just by adding that one line in the controller, all the restful actions and their corres...

Installed Rails but the rails command says it's not installed.

Hey there, I'm using Ubuntu 9.10 Karmic Koala and Ruby 1.9.1. I installed Rails using sudo gem install rails, which installed all the libraries for me. When I type rails in the terminal it says. The program 'rails' is currently not installed. You can install it by typing: sudo apt-get install rails rails: command not found I can fi...

In Rails, how can I return a set of records based on a count of items in a relation OR criteria about the relation?

I'm writing a Rails app in which I have two models: a Machine model and a MachineUpdate model. The Machine model has many MachineUpdates. The MachineUpdate has a date/time field. I'm trying to retrieve all Machine records that have the following criteria: The Machine model has not had a MachineUpdate within the last 2 weeks, OR The Mac...

Can't update RubyGems

Hi! I'm having difficulties updating RubyGems from version 1.1.1 to newest. I've tried the following: gem update Result: Updating installed gems Bulk updating Gem source index for: http://gems.rubyforge.org/ Nothing to update and gem install rubygems-update Result: Bulk updating Gem source index for: http://gem...

Mysql Constraign Database Entries in Rails

I am using Mysql 5 and Ruby On Rails 2.3.1. I have some validations that occasionally fail to prevent duplicate items being saved to my database. Is it possible at the database level to restrict a duplicate entry to be created based on certain parameters? I am saving emails to a database, and don't want to save a duplicate subject line...

Asking Rails What Plugins it has Loaded, After Initialization

At some point, this was valid: Rails.plugins But I cannot seem to make this work for me in Rails 2.3. What is the proper strategy to ask Rails about plugins that have been loaded, after its initialized them all? ...

Rails nested attributes javascript add another

I had a model with some nested attributes and needed to add new items via Javascript. This is what I came up with: $('.add_task').click(function() { var last_item = $('#tasks li:last'); last_item.after('<li>'+last_item.html().replace(/\d+(?=\_)|\d+(?=\])/g, function(match) {return parseInt(match)+1;})+'</li>'); }); It does the job...

RoR development-environment setup.

I'm interested to play around with RoR a bit. Apart from literature i should read, i'm particularly interested about how to setup development environment. Here's a good example how to setup environment for Java from Noda Time project wiki pages. I want something similar but for RoR. As far as i know - unix operation systems fits way mu...

Regular Expression Attack Vector?

How does one "parameterize" variable input into a Regex in Ruby? For example, I'm doing the following: q = params[:q] all_values.collect { | col | [col.name] if col.name =~ /(\W|^)#{q}/i }.compact Since it (#{q}) is a variable from an untrusted source (the query string), I have to assume it could be an attack vector. Any best practice...

Ruby On Rails in MAMP mySQL Snow Leopard

I'm trying to find step-by-step instructions to run Ruby on Rails on MAMP server and use MAMP's mySQL database. I am on Snow Leopard also. I have read Hivelogic's article about this but I really don't want to compile rails, ruby and mySQL. Anyone have any suggestions ...

Case sensitive find in Rails

I'm using Mysql with collation utf8_general_ci and for most of my searches it is good. But for one model and one field I want to find a record with case sensitive. How to do it? ...

Using Formtastic and Globalize2 together

I use Formtastic. Now I would like to add model translations for some fields. I look at Globalize2 and it seems like what I need. But I have no idea how to integrate it with Formtastic. Does anybody have such experience? ...

Rendering other controllers' templates (Ruby on Rails)

I am building a sample site to familiarize myself with RoR. I followed the book "Agile Web Development with Rails" up to a point, and now I am experimenting and using it as a reference, however I haven't been able to find the answer to my problem. I have two models of interest, one is supermarketchain and the other supermarket. Obvious...

Displaying Data in form after using activerecord

Hello, I have a form that the user is going to interact with, by updating, etc. The data is being pulled from the database, so that the user can see previous data and add new ones as well. So basically when I try to execute the code below, I get an error, saying that there is no method... @display = Sales.find(:all, :conditions => ['...

Ruby on Rails: Drop down menu

Hi, I'm trying to create a drop down menu to allow a user to change an entry's field in my table. The user has one of three options -- hot, medium and cold. I already have text_fields that do essentially the same thing for other fields, that all update when the user clicks on a submit_tag. Is there an easy way to implement a drop-do...

trigger jQuery function after location.reload() completes

I have a Rails app that allows users to login via jQuery modal form. Once logged in, I refresh the original page using location.reload(). At this point, I'm attempting to create a new jQuery dialog. How can I open the dialog only after location.reload() has finished executing? Right now the dialog is loading up before location.reload...

How to over ride the autosave option for a has_many collection at an object level?

class Article has_many Comments end class Comments belongs_to Article end # Logic for importing Comments and Ratings a = Article.find_by_name(name) a.comments = comments # comments list gets saved. # I want to delay this # # some other logic # Article.transaction # save Comments # save Ratings end In the ...

Ignoring specific validation errors

I have Labellings which belong to Emails and Labels. Each labelling must be unique to the email/label pair - so an email can only be labelled 'test' once. I'm doing this with validates_uniqueness_of :label_id, :scope => :email_id. This works as expected. When I am labelling emails, I want to add the labelling if it is unique, and do n...

Retrieve OpenID AX attributes from Google / Yahoo in Rails

I'm using the rails plugin open_id_authentication in my app. This works for MyOpenID, however authenticating with Google I can't get the email address as part of the required attributes. From what I understand, Google ignores sreg attribute requests, and only listens to the AX schema for email address. Here's my code: def open_i...

ORM alternatives to ActiveRecord

To begin with this post in no ways undermines ActiveRecord. I am pretty happy with it, but for the sake of knowledge and to try a few options are there any other alternatives to ActiveRecord available? Has anybody used some other ORM than ActiveRecord, if yes then which ORM is that? Please share your experience. ...