July 25, 2007 at 7:29 am
· Filed under Ruby on Rails, Software, The Web
Problem: I wanted to display all columns when doing an update or create of a model but when that model was to be updated or created in a subform of an associated model’s create or update I only wanted certain columns (the required ones) to be displayed.
Solution: config.subform.columns.exclude :field_name
So, if a user is to be edited and the user groups appear as a subform in the scaffold, the snippet above must be in the code for the user group, NOT the user. If you don’t want to include the group category and group note in the user update scaffold, the line of code in the groups_controller would be config.subform.exclude :category, :note
Permalink
July 20, 2007 at 10:18 am
· Filed under Ruby, Ruby on Rails, Software, The Web, Uncategorized
This image is useful in illustrating data model relationships in Ruby on Rails.
http://mboffin.com/stuff/ruby-on-rails-data-relationships.png
Permalink
July 13, 2007 at 12:58 pm
· Filed under Ruby on Rails, The Web
Use this method in your controller to restrict the items to be displayed in your list to those that meet the conditions set in the method. The example from the ActiveScaffold wiki is as follows:
def conditions_for_collection
['user_type IN (?)', ['admin', 'sysop']]
end
Permalink
July 12, 2007 at 2:48 pm
· Filed under Ruby, Ruby on Rails, Software
When creating an implicit mapping table (habtm table) to join two otherwise unrelated tables (e.g. groups and projects) that have a habtm relationship and have primary keys, make sure that the mapping table does not have an id column but adding the ‘, :id => false’ before the ‘do’ in your migration setup. If this is not done there will be errors related to the primary key when you attempt to add new relationships.
From the rubyonrails.org docs: “When you create your habtm table, make sure to leave out the “id” column. Otherwise, the habtm join table id will be populated to contain the id of your joined model, not an auto-inc number. this, of course, leads to trouble.”
Permalink