Displaying 20 results from an estimated 10000 matches similar to: "Best route for has_many subrecords"
2006 Aug 16
1
Naming rights_roles join model using has_many :through and polymorphic associations
Hi.
I have a couple of best practices questions regarding polymorphic
associations, naming join tables and user permissions.
Currently I have implemented the user authentication model from the
rails recipes book. Basically it goes something like this:
MODEL CLASSES:
class User < ActiveRecord::Base
has_and_belongs_to_many :roles
end
class Role < ActiveRecord::Base
2007 Dec 20
0
polymorphic has_many :through Vs Inheritance
Hi everyone.
Ive part of a project that I need to refactor, and im having some
difficultly deciding which path to take. Perhaps someone can help, I
think its primarily a design question.
A Spec consists of many Nests and many Parts. Nests contain Parts.
Here''s what I have, which works well currently:
---------------------------------------------------
class Spec <<
2009 Apr 18
1
RESTful Routing: Getting names of resources out of paths
Hello -
I''m trying to remain RESTful in a new application that I''m building, but
I''m not sure how to get the routes that I want. I''m trying to avoid
having resource names like "posts" and "comments" cluttering things up.
For example, for a resource that I designate:
GET example.com -> index
GET example.com/1 -> show, id=1
GET
2010 Mar 23
1
:has_many and :controller specified in routes.rb
Have an app using older version of Rails (2.3.2) that I need some
routing assistance with if anyone has a minute.
The app was originally designed to be purely html view, and an xml and
json api was hacked on. To keep it clean, we are now moving the first
version of the api (v1) under its own directory (v1) under app/
controllers but still responding to the old paths.
One of the parts of the new
2009 Dec 10
2
How to customize the default scaffold?
I know the scaffold generator is really only useful for beginners
and/or very the preliminary state of a project, but I find that I use
it a lot (especially, since I am still a beginner). There are a
couple of things I find myself tweaking (or wanting to tweak, but
never getting around to tweaking) each time I generate a new scaffold:
1) Change the layout from blah.html.erb to
2008 Mar 12
2
nested routes with a 2-way has_many using join table?
I have two classes, InstructionalObject and Assets. They both have_many
of the other, implemented through a join table (so it''s like a habtm
without the habtm).
For the next version of our app, we''re refactoring to RESTful, and i''m
having trouble with my nested resources/routes. I tried this, in
routes.rb:
map.resources :assets do |assets|
assets.resources
2009 Oct 14
6
Reinstantiate controller during functional testing
... ok, I may be going about this the wrong way, or perhaps, a less
efficient way than is optimal, but I would like to test a little bit
of AJAX on one of my web pages. When I test this by hand, I bring up
the page which shows a select box, I select an item from the drop down
list, see another select box show up, go back to the first select box,
select a different item, and see something
2006 Aug 13
4
has_many and foreign_key question
Alright, noob here, etc. etc.
Trying to figure out the has_many usage. If I understand correctly, when
you declare that a table/class has_many whatevers, the rails assumption
is that there will be a foreign key in the whatevers table pointing back
to the ''id'' primary key in the first table. This doesn''t seem to be the
only way to have a ''has_many''
2009 Sep 28
6
What is the most efficient way to split a table into 2 groups?
I have the following:
@lot = Lot.find(params[:id])
part_nums = Part.all(:conditions => ["id <> ?", @lot.part.id])
I guess I should mention that
Lot :belongs_to => :part
I was looking at the log following the execution of these two
statements and I saw something like this:
Lot Load (0.4ms) SELECT * FROM "lots" WHERE ("lots"."id" = 13)
Part
2010 Jun 17
0
Edge Rails Nested has_many :through Association
So this functionality isn''t supported natively in Rails 3 (or any
versions before that for that matter) But I had found a work around
via this blog post: http://geoff.evason.name/2010/04/23/nested-has_many-through-in-rails-or-how-to-do-a-3-table-join/
This didn''t work on Rails 3 because it wasn''t able to properly build
the query from the join with symbols. I was
2007 Aug 25
4
REST routes :has_many , new style
I am trying to write a nested route ''new style''
map.resources :franchises, :has_many => :documents
in place of the :
map.resources :franchises do |franchises|
franchises.resources :documents, :name_prefix => "franchise_"
end
but get an error :
no route found to match "/franchises/1/documents" with {:method=>:get}
running rake routes,
2008 Dec 13
2
What is "The Rails Way" to do this?
I have a PHP application with the following in one of the "views":
<input type="button" onClick="newAlt()" value=" + "></nobr>
The JavaScript for "newAlt()" is:
// using DOM create new input box for alternate part
function newAlt() {
var html = "<input style=''background-color:#FFFFCC'' ";
html +=
2006 Apr 20
3
has_many :through with has_many/has_many join models
It seems that using a join model that joins with two has_many''s will
fail to generate proper SQL
class StudentSemesterRecord < ActiveRecord::Base
belongs_to :semester
has_many :discipline_records, :through => :semester
end
class Semester < ActiveRecord::Base
has_many :student_semester_records
has_many :discipline_records
end
class DisciplineRecord <
2009 Jan 10
0
has_many in routes.rb
Hi
I saw
map.namespace(:admin) do |admin|
admin.resources :accounts, :has_many => [ :credentials ]
end
and I wrote like
map.namespace(:admin) do |admin|
admin.resources :accounts do |account|
account.resources :credentials
end
end
The only difference I found is, in the first no helper methods
are generated..I would like to know is that the
2006 May 16
0
Possible bug: ActiveRecord::Base::has_many fails for String arguments.
Hi
I''ve noticed ActiveRecord::Base::has_many fails for String arguments.
The following code works when all arguments to the
ActiveRecord::Base::has_many calls are Symbols:
class Country < ActiveRecord::Base
has_many :country_products, :dependent => true
has_many :products, :through => :country_products
end
ruby script/console
>> Country.find_all.first.products
2006 Apr 03
0
has_many questions
My application has two models I''d like to have multiple join tables
between, Users and Groups. Users have the ability to subscribe to a
Group, while a Group would like to know its membership.
Additionally, a User can administer several Groups and a Group should
know about its several Administators (Users).
I have the following declarations:
class Administrator <
2006 Mar 24
2
Change to has_many :through associations
Hi everyone. I''ve made a default change to has_many :through
associations that I felt was important to make before they''re
released. This is after some tickets and confusion I''ve seen
regarding has_many :through.
class Connection < ActiveRecord::Base
belongs_to :user
belongs_to :channel
end
class Channel < ActiveRecord::Base
has_many :connections
2010 Jan 25
0
has_many, :finder_sql, setting attributes
Hi all,
My question is somewhat complicated, but bear with me. My project has a
number of models: User, Program, and Team. Users belong to multiple
Programs. Programs have multiple teams, but Teams belong to one
program. For each Program a User belongs to, he can belong to multiple
Teams. (Think of this in an athletic context where users are athletes,
programs are universities). So my
2009 Nov 12
0
Problem with has_many :through, :uniq => true with polymorph
Didn''t have quite enough space to describe it there...basically i''m
having a problem with the :uniq option in my tags.
I''m using acts_as_taggable_on_steroid which adds these associations to
my Resource class:
Resource
has_many :taggings, :as => :taggable, :dependent => :destroy, :include
=> :tag
has_many :tags, :through => :taggings, :uniq => true
2005 Dec 26
2
Dynamic order on has_many relationship?
I was wondering if it''s possible to some how control the :order given
on a has_many depending on another attribute?
Or do I need to just create multiple has_many relationships pointing
to the same table but with different orders and then select which one
I use in the controller instead?
e.g
class Category < AR::B
has_many :products, :order => //something magical?//
end