ruby-on-rails

How to model a "can belong to A or B" relationship in Rails?

I'm a newbie to RoR - I have three models: Customer, Job and Note. Customers have Jobs, and both Customers and Jobs can have Notes. Is there a special way to handle this type of relationship in Rails, or will it work if I just have a normal belongs_to relationship with Note? The issue that concerns me is the note having fields for ...

Rails directory database structure

Hi! I'm building a "small" personal web app in Ruby on Rails. I've set it up so that I'm using a MySQL database. The idea is that I'm gonna store and navigate many kinds of data (notes, bookmarks, movie and appliction ratings) with this app. I want to index/categorise this data in a pseudo-directory structure. (The directory structure ...

Rails cannot find model with same name as Ruby class

I'm fairly new to Ruby on Rails, and I have a project with a "Set" model. This is in Rails 2.3.2. Now the problem is that it can't find any methods on that model's class at all. For example: "undefined method find' for Set:Class" or "undefined method errors' for #". It seems to be trying to find those methods on the Ruby "Set" class inst...

Rendering an externally modified file in Rails

I've got a cron job parsing a few XML feeds every ten minutes and creating a few partials to include on every page in my Rails project with the render: file method. The problem is that, obviously, they don't refresh until the server restarts. Anyway, what can I do to force rails to refresh this file every time? Thanks in advance. ...

one line hash creation in ruby

How can I, very simply construct a hash in ruby using something simple like "times" I have a @date (ie = Date.today) and then a number of days... say 5 5.times { |i| @date_range[:day] = (@date+i).strftime("%Y-%m-%d") } I know there's got to be something super simple that's missing. Thanks... ...

How to label :id in Ruby on Rails apps?

I am building my first rails application and I expect it to eventually have many models/controllers. And of course they each have an ID associated with them. I can see that they are starting to get confusion already. In the users controller the field is called id, but in every other controller i label it as user_id. When a controller...

Adjustments needed in a Rails app to use Datamapper instead of ActiveRecord

I am trying to use Datamapper in a Rails app as an alternative to ActiveRecord. I've followed the various setup instructions and have Datamapper working in my app. But one of the first things I noticed that no longer works is this: <%= f.error_messages %> I believe this is tied to an ActiveRecord helper - is there an alternative w...

Redirects with Datamapper & Rails

I have a line in my routes.rb to map my Album model as a resource: map.resources :albums However, using Datamapper in place of ActiveRecord in Rails, why would this line: format.html { redirect_to(@album) } cause a redirect to: albums/%23<Album:0x72d452c> instead of: albums/1 In case further context is needed, my full crea...

ActiveRecord dynamic attribute-based finders with Union Logic?

I want 'logical OR' dynamic finders in ActiveRecord. Anybody seen such a thing? So in the spirit of something like this.. User.find_by_name_and_email("foo", "[email protected]") .. you could do stuff like this.. User.find_by_username_or_email(user_input) ...

How do you debug a Rails application?

Is it possible to debug a Rails application in a similar way to a Java application - setting breakpoints and stepping into the code? What are the best tools for this? I have a hybrid Java/Ruby on Rails application which I can run in Eclipse or Netbeans. I would like to step into some code in this app and try to figure out the cause of...

How do I edit multiple records in one Ruby on Rails form?

I'm making a simple to-do list application to teach myself Ruby on Rails, however I've run into a problem. I have a simple form that lists to-do items with a check box to the left of them, and an "Update" button at the bottom, as so: [ ] Do the dishes [ ] Take out the garbage [ ] Take over the world ( Update ) Each to-do item is a sepa...

(Ruby,Rails) Context of SELF in modules and libraries...?

Hi All, Quick question regarding the use of "SELF" inside a module or library. Basically what is the scope/context of "SELF" as it pertains to a module or library and how is it to be properly used? For an example of what I'm talking about, check out the "AuthenticatedSystem" module installed with "restful_authentication". Best NOTE:...

(Ruby,Rails) Role-based authentication and user management...?

Hi All, I'm looking for a quality Administrative plugin for Rails. It seems that most of the existing plugins/gems (e.g. "restful_authentication", "acts_as_authenticated") revolve around self-signup, etc. However, I'm looking for a full-featured Administrative/Management role-based type of solution -- but not one that's simply tacked ...

undo scaffolding in rails

Is their anyway to 'undo' the effects of a scaffold command in rails? ...

How to translate and modify map.resources :document

map.resources :document After adding this route, I now have an automatic "edit_document_path". I wanted to change this to "annotate_document_path"? Will it automatically pick this up if I add a new view and controller method? How does it translate from the resource route to these "path" notations? ...

Sanitizing data at active record

Hi guys, I waan sanitize the data coming from my form in my active record .Especially the single inverted comma before its actually jacked into the sql query. I want it to be something raghu'\s if raghu's is been fed.let me know if there is something at activerecord level that can do this job for me !!! ..I have already tried using sa...

In Ruby, should I use ||= or if defined? for memoization?

Should I use if defined? return @current_user_session if defined?(@current_user_session) @current_user_session = UserSession.find Or ||= @current_user_session ||= UserSession.find I noticed the if defined? method being used more and more recently. Is there any advantage to one over the other? Personally, I prefer ||= for readab...

howto use activeresource on rails 1.2.3 (cc.rb)

Hi, I'm working on a cc.rb plugin and need activeresource support. as cc.rb runs on rails 1.2.3, there is no activeresource support. is there a way to use activeresource on rails 1.2.3, since i don't want to upgrade cc.rb to rails 2.3.2? thx ...

Can Ruby on Rails connect to Oracle/RDB on Mac OS X or Windows?

I have an older database Oracle RDB. I used ODBC on Windows with .net, but I'm not sure how to proceed on RoR on a Mac OS X server. I don't know how I do it on Windows either with RoR. I was hoping for general direction. EDIT: I searched for activerecord and rdb but have nto found it yet. I saw references to rdb$database and so on ...

Cloning attributes of one object to the other

I have two models Content and ContentType. Each Content (class not object) has its associated ContentType and ContentType basically holds some attributes that could be set using online form, which then can be used in the views to show/hide some of the content objects attributes. After creating a new Content object (ex: @c = Content.new...