Search Results

Search found 1021 results on 41 pages for 'has and belongs to many'.

Page 3/41 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • has_many through a habtm relationship in Rails

    - by macek
    I'm trying to define a has_many X, :through => Y where Y is a habtm relationship. Rails is throwing a fit about this. See comment in user model: class User < ActiveRecord::Base has_many :posts # I want to display a list of all tags this user is involved in has_many :tags, :through => :posts # ERROR end class Post < ActiveRecord::Base has_and_belongs_to_many :tags end class Tag < ActiveRecord::Base has_and_belongs_to_many :posts end What can I do to fix this?

    Read the article

  • Associating Models with Polymorphic

    - by Josh Crowder
    I am trying to associate Contacts with Classes but as two different types. Current_classes and Interested_classes. I know I need to enable polymorphic but I am not sure as to where it needs to be enabled. This is what I have at the moment class CreateClasses < ActiveRecord::Migration def self.up create_table :classes do |t| t.string :class_type t.string :class_name t.string :date t.timestamps end end def self.down drop_table :classes end end class CreateContactsInterestedClassesJoin < ActiveRecord::Migration def self.up create_table 'contacts_interested_classes', :id => false do |t| t.column 'class_id', :integer t.column 'contact_id', :integer end end def self.down drop_table 'contacts_interested_classes' end end class CreateContactsCurrentClassesJoin < ActiveRecord::Migration def self.up create_table 'contacts_current_classes', :id => false do |t| t.column 'class_id', :integer t.column 'contact_id', :integer end end def self.down drop_table 'contacts_current_classes' end end And then inside of my Contacts Model I want to have something like this. class Contact < ActiveRecord::Base has_and_belongs_to_many :classes, :join_table => "contacts_interested_classes", :foreign_key => "class_id" :as => 'interested_classes' has_and_belongs_to_many :classes, :join_table => "contacts_current_classes", :foreign_key => "class_id" :as => 'current_classes' end What am I doing wrong?

    Read the article

  • How many copies of files are needed by video server?

    - by Trilok
    A quick question. How many copies of the same movie are kept in a video server (a video streaming server)? Suppose a particular video is at max requested by 1000 users at the same instant of time, how many copies would be sufficient so that parallel streams can be provided to each user? Ideally 1 copy would solve the purpose, but what is the optimum number keeping the bandwidth and simultaneous access in mind?

    Read the article

  • nested form & habtm

    - by brewster
    so i am trying to save to a join table in a habtm relationship, but i am having problems. from my view, i pass in a group id with: = link_to "Create New User", new_user_url(:group => 1) User model (user.rb) class User < ActiveRecord::Base has_and_belongs_to_many :user_groups accepts_nested_attributes_for :user_groups end UserGroups model (user_groups.rb) class UserGroup < ActiveRecord::Base has_and_belongs_to_many :users end users_controller.rb def new @user = User.new(:user_group_ids => params[:group]) end in the new user view, i have access to the User.user_groups object, however when i submit the form, not only does it not save into my join table (user_groups_users), but the object is no longer there. all the other objects & attributes of my User object are persistent except for the user group. i just started learning rails, so maybe i am missing something conceptually here, but i have been really struggling with this.

    Read the article

  • declarative authorization and has_and_belongs_to_many

    - by Michael Balsiger
    Hi, I have a little problem with declarative-authorization. I have a User and Role Model with a has_and_belongs_to_many association. I've created a Role named :moderator in my authorization_rules.rb Is it possible that a User with the Role Moderator only gets the Users that have the Moderator Role assigned to it?? -- User.with_permissions_to(:index) I thought it would be possible like that: role :moderator do has_permission_on :users, :to => :index do if_attribute :roles => contains { ????? } end end I also created a named_scope in my User Model because I thought it would help... class User has_and_belongs_to_many :roles named_scope :by_role, lambda { |role| { :include => :roles, :conditions => {"roles.name" => role} } } end Does anyone knows if it's possible to do this with declarative_authorization? Thanks for your help!

    Read the article

  • List of free hosted domains (phishing prevention)

    - by nigative
    Does anyone has a compiled list of free hosting domains? On the website, when user clicks on external link I want them to be redirected to my page that will check if that external link is on free hosting or not. If it is, I want to warn the user, but right now I can't find a list of such domains. Any help?

    Read the article

  • Ubuntu problem not connecting to wireless or wired network

    - by ToughPal
    I recently installed openvpn and things were working. But I got a weird screen after a few hours and on restart my wired and wireless connections are not working. Can someone help? cat /etc/network/interfaces auto lo iface lo inet loopback cat /etc/resolv.conf #Generated by NetworkManager Is there anything missing? I tried both wired and wireless and both are not working. Usually if I ever have a problem with wireless, the wired always work! My /etc/network/interfaces is looking wrong. Can you please send me yours? I am using ubuntu 9.10 and the internet was working correctly until today! Please help

    Read the article

  • Simulating a belongs_to_many in rails

    - by DavidP6
    I have a situation where in theory I would need to use a belongs_to_many relationship. I have an Example model and a Sentence model. Each example object has one sentence but these sentences are not necessarily unique. So, for example, I could have two example models that each have one sentence that is the same sentence. I'm not sure how to go about doing this in rails. I tried using has_and_belongs_to_many, but ran into problems. It seems that I only need the belongs_to :many part of that relationship. Ideally it would look something like this, but I know there is no belongs_to :many. Example has_one :sentence end Sentence belongs_to_many :examples end

    Read the article

  • How to Join Multiple MP3's using LAME

    - by Ole Jak
    I have N mp3s ( N files for example). I need to Join (impose) them into 1. I mean I want to to mix sounds like the N speakers speak at the same time, please help. Any key to special LAME function for performing such operation? Thanks.

    Read the article

  • CakePhp: model recursive associations and find

    - by Petecocoon
    Hello to everybody! I've some trouble with a find() on a model on CakePhp. I have three model relationed in this way: Project(some_fields, item_id) ------belongsTo----- Item(some_fields, item_id) ------belongsTo----- User(some_fields campi, nickname) I need to do a find() and retrieve all fields from project, a field from Item and the nickname field from User. This is my code: $this->set('projects', $this->Project->find('all', array('recursive' => 2))); but my output doesn't contains the user object. I've tried with Containable behaviour but the output is the same. What is broken? Many many Thanks Peter

    Read the article

  • Will the other directories on my C drive still be visible?

    - by user225626
    My Windows 7 ate itself, corrupted a few files, now refuses to boot. On the same drive were other directories of various assorted non-Microsoft applications I like to use. After the crash, I have been mounting those from outside (as F:[whatever]). If I go ahead and reinstall Windows 7 on that drive and use the drive again as my primary, will those other directories be visible to it from inside? Meaning if I boot up my new installation of Windows from within that drive, will I be able to see those other old directories via Windows Explorer on the C drive (where any haven't been run over by the reinstalled OS)? Thanks for any help.

    Read the article

  • Windows 7 - XP Mode - Apache

    - by Howard
    I've setup Virtual PC and XP Mode on my Windows 7 Pro. Using Apache 2.0.52 I have no problems having my website up and running on the Windows 7 machine. But Under VPC/XP Mode the best I can do is Localhost mode. What do I need to do to enable http connections? I need the XP Mode as besides the website I also run a Web BBS and a Dos based (via telnet) BBS. Some of the apps in the Dos BBS just won't work under 64 bit, no matter what setting (capability) are used. Thanks in advance...

    Read the article

  • retrieving google chrome booksmarks after uninstall

    - by Rees
    Hello, I had recently (and unfortunately) uninstalled the google chrome browser from my computer -while completely forgetting about the dozens of bookmarks I had stored on it. Is there a method/directory to retrieve these chrome bookmarks after having already uninstalled??? Please do help! would be a lifesaver!

    Read the article

  • Undefined method for a belongs_to association

    - by marimaf
    My code: class User < ActiveRecord::Base belongs_to :university end class University < ActiveRecord::Base has_many :users, dependent: :destroy end and my model User has a university_id attribute. If I do University.find(1).users I get the list of users, but if I do User.find(1).university (and I checked that university_id is not nil here) I get: NoMethodError: undefined method `university' for from /home/mari/.rvm/gems/ruby-1.9.2-p290/gems/activemodel-3.0.10/lib/active_model/attribute_methods.rb :392:in `method_missing' from /home/mari/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.10/lib/active_record/attribute_methods. rb:46:in `method_missing' from (irb):14 from /home/mari/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/commands/console.rb:44:in sta rt' from /home/mari/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/commands/console.rb:8:in star t' from /home/mari/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/commands.rb:23:in <top (requi red)>' from script/rails:6:inrequire' from script/rails:6:in `' What am I doing wrong? I have another models and they are working just fine. Any suggestions? Thanks in advance

    Read the article

  • Two Different Types of Associatons on the Same Two Tables in Rails

    - by tmo256
    I have two models, users and themes, that I'm currently joining in a HABTM association in a themes_users table. Basically, after a user creates a new theme, it becomes available to other users to select for their own use. However, only the original creator of the theme should have the ability to edit it. So, I need to have some other kind of association to handle that relationship, something like an created_by_id field in the theme. In this way, the user model acts as two different roles: they can be an implementer of a theme AND/OR the owner of the theme. The implementer relationship is handled by the themes_users join table; the question is: What is the right way to handle this secondary association? Do I need to make users polymorphic and then make the created_by_id reference an "owner"? Or is there something easier? Thanks so much for your help!

    Read the article

  • Double join with habtm in ActiveRecord

    - by Daniel Huckstep
    I have a weird situation involving the need of a double inner join. I have tried the query I need, I just don't know how to make rails do it. The Data Account (has_many :sites) Site (habtm :users, belongs_to :account) User (habtm :sites) Ignore that they are habtm or whatever, I can make them habtm or has_many :through. I want to be able to do @user.accounts or @account.users Then of course I should be able to do @user.accounts < @some_other_account And then have @user.sites include all the sites from @some_other_account. I've fiddled with habtm and has_many :through but can't get it to do what I want. Basically I need to end up with a query like this (copied from phpmyadmin. Tested and works): SELECT accounts.* FROM accounts INNER JOIN sites ON sites.account_id = accounts.id INNER JOIN user_sites ON sites.id = user_sites.site_id WHERE user_sites.user_id = 2 Can I do this? Is it even a good idea to have this double join? I am assuming it would work better if users had the association with accounts to begin with, and then worry about getting @user.sites instead, but it works better for many other things if it is kept the way it is (users <- sites).

    Read the article

  • HABTM checking for match of latest 3

    - by user333614
    Here's an interesting one for you folks... I have a HABTM (has_and_belongs_to_many) relationship between "Dogs" and "Trips". My goal is to find two result sets: 1) Dogs that have been on at least 1 of the last 3 trips and call that @dogs_current 2) Dogs that have NOT been on any of the last 3 trips and call that @dogs_old I found that I can find what the last 3 trips are by doing this in the Trip model: named_scope :last3, :order => 'date DESC', :limit => 3 But not sure how to use that list get 1 and 2. This hack works, but it seems ugly. There must be a better way! :) @dogs_current = [] @dogs_old = [] @dogs.each do |dog| if (Trip.last3 - dog.trips).size < 3 then @dogs_current << dog else @dogs_old << dog end end Any ideas? Thanks! -Cam

    Read the article

  • Rails - HABTM Relationship -- How Can I Find A Record Based On An Attribute Of The Associated Model

    - by ChrisWesAllen
    I have setup this HABTM relationship in the past and its worked before....Now it isnt and I'm at my wits end trying to figure out whats wrong. I've looking through the rails guides all day and cant seem to figure out what I'm doing wrong, so help would really be appreciated. I have 2 models connected through a join model and I'm trying to find records based an attribute of the associated model. Event.rb has_and_belongs_to_many :interests Interest.rb has_and_belongs_to_many :events and a join table migration that was created like create_table 'events_interests', :id => false do |t| t.column :event_id, :integer t.column :interest_id, :integer end I tried @events = Event.all(:include => :interest, :conditions => [" interest.id = ?", 4 ] ) But got the error "Association named 'interest' was not found; perhaps you misspelled it?"... which I didnt of course I tried @events = Event.interests.find(:all, :conditions => [" interest.id = ?", 4 ] ) but got the error "undefined method `interests' for #Class:0x4383348" How can I find the Events that have an interest id of 4....I'm definitely going bald from this lol

    Read the article

  • How to set up two models having a has_many association with each other

    - by daz13
    I'm looking for a suggestion on how to set up two models, Teacher and Subject. A Teacher can have many Subjects, and a Subject can have many Teachers. Another thing to consider in the relationship between the two models is that a Teacher can create a Subject and add other Teachers to the Subject. I think I'm solid on the basics of the set up for each model: for teacher.rb: has_many :subjects for subject.rb: has_many :teachers and the teachers table should have a subject_id column and the subject table should have a teacher_id column. What I'm not sure about is how to set up the views (and corresponding controller methods) to allow the addition of a Teacher to a Subject. Any suggestions (or links to examples) are greatly appreciated. I haven't been able to find anything on this exact case.

    Read the article

  • acts_as_list with has_and_belongs_to_many relationship

    - by mculp
    I've found an old plugin called acts_as_habtm_list - but it's for Rails 1.0.0. Is this functionality built in acts_as_list now? I can't seem to find any information on it. Basically, I have an artists_events table - no model. The relationship is handled through those two models specifying :has_and_belongs_to_many How can I specify order in this situation?

    Read the article

  • How do I determine that an instance of org.apache.poi.hwpf.model.ListData belongs to a numbered lis

    - by leighgordy
    Is there a way to determine if an instance of a org.apache.poi.hwpf.model.ListData belongs to a numbered list or bulleted list? I am using Apache Poi's org.apache.poi.hwpf.HWPFDocument class to read the contents of a word document in order to generate HTML. I can identify the list items in the document by checking to see that the paragraph I am working with is an instance of org.apache.poi.hwpf.model.ListData. I can not find a way to determine if ListData belongs to a bulleted list or a numbered list.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >