Hello, I have two tables with association HABM, projects and users, and in projects I want to show all users that was associated to the project. I have try with this: <%= select( "user", "id", Project.all.collect { |p| [ p.name, p.id ] } ) %> But only show all my projects, but Iz don''t know who show only the user in a determinated project. class Project < ActiveRecord::Base has_attached_file :image, :styles => { :medium => "300x200>", :thumb => "100x100>" } has_many :item has_and_belongs_to_many :users belongs_to :category belongs_to :color belongs_to :icon # kaminari # https://github.com/amatsuda/kaminari paginates_per 6 end class User < ActiveRecord::Base has_and_belongs_to_many :projects end Thank you for the help. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 5 March 2012 21:00, Felipe Pieretti Umpierre <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hello, I have two tables with association HABM, projects and users, and > in projects I want to show all users that was associated to the project.If you have a project in @project for example, then to get all the associated users you just use @project.users That is the magic of Rails. I suggest that you work right through a good tutorial such as railstutorial.org (which is free to use online), then you will get a grasp of the basics of Rails. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 5 March 2012 21:04, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 5 March 2012 21:00, Felipe Pieretti Umpierre <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Hello, I have two tables with association HABM, projects and users, and >> in projects I want to show all users that was associated to the project. > > If you have a project in @project for example, then to get all the > associated users you just use > @project.users > That is the magic of Rails. > > I suggest that you work right through a good tutorial such as > railstutorial.org (which is free to use online), then you will get a > grasp of the basics of Rails.Also have a look at the Rails Guide on Associations, and all the others in fact. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>Colin, > >@project.users >That is the magic of Rails.This magic I already know, but my question was, I want to show All user associated in a project in a select tag. But I don''t know if I make a each in @project.users and do a each or has something already done with rails. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 5 March 2012 21:17, Felipe Pieretti Umpierre <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:>>Colin, >> >>@project.users >>That is the magic of Rails. > > This magic I already know, but my question was, I want to show All user > associated in a project in a select tag. > > But I don''t know if I make a each in @project.users and do a each or has > something already done with rails.Sorry I misread what you wanted, I will replied again to the original mail Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 5 March 2012 21:00, Felipe Pieretti Umpierre <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hello, I have two tables with association HABM, projects and users, and > in projects I want to show all users that was associated to the project. > > I have try with this: > > <%= select( "user", "id", Project.all.collect { |p| [ p.name, p.id ] } ) > %> > > But only show all my projects, but Iz don''t know who show only the user > in a determinated project.The code you have will show all projects because you have specified Project.all. I don''t understand exactly what you want to show. Do you want the users to appear in a select box or what? Do you have a particular project? Is it in a variable? Please be a bit more specific about what you want to see on the page. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hello Colin, thank you for Ur attention. I have a model Project, in my projects I can create items, in this project I can Select various user, that will be available in my items to distribute that users that I select to make part of my project. But when I try to make a select of all users that are in this project, I can''t because I don''t know very well rails yet, and don''t know if have something already done or I will have to improvise. Thank you again -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Do u mean double select ? You have two select drop down, and u want the second one contains only the users which belongs to the selected project in the first select drop down ? 3dd13 developer http://3dd13.me On 6 Mar, 2012, at 7:29 AM, Felipe Pieretti Umpierre <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hello Colin, thank you for Ur attention. > > I have a model Project, in my projects I can create items, in this > project I can Select various user, that will be available in my items to > distribute that users that I select to make part of my project. > > But when I try to make a select of all users that are in this project, I > can''t because I don''t know very well rails yet, and don''t know if have > something already done or I will have to improvise. > > Thank you again > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 5 March 2012 23:29, Felipe Pieretti Umpierre <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: Please don''t top post, it makes it difficult to follow the thread. Insert your comments at appropriate points in previous message. Thanks Also by completely removing the previous message here you have lost all context so nobody finding this in the future will know what the post is about.> Hello Colin, thank you for Ur attention. > > I have a model Project, in my projects I can create items, in this > project I can Select various user, that will be available in my items to > distribute that users that I select to make part of my project. > > But when I try to make a select of all users that are in this project, I > can''t because I don''t know very well rails yet, and don''t know if have > something already done or I will have to improvise.Previously you showed a select that used Project.all to get the projects to display. Now you say you have a particular project (let us assume, since though I asked you did not answer the question) that it is in @project. Then all you have to do is use a select similar to the one you already had, but use @project.users instead of Project.all. Obviously you have to change the contents of the collect block also as it will be receive users instead of projects. How are you getting on with working through railstutorial.org? You should be well on the the way through it by now. If you had completed it you would not have needed to ask this question. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.