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@googlegroups.com.
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.

Search Discussions

  • Colin Law at Mar 5, 2012 at 9:05 pm

    On 5 March 2012 21:00, Felipe Pieretti Umpierre 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@googlegroups.com.
    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.
  • Colin Law at Mar 5, 2012 at 9:08 pm

    On 5 March 2012 21:04, Colin Law wrote:
    On 5 March 2012 21:00, Felipe Pieretti Umpierre 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@googlegroups.com.
    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.
  • Felipe Pieretti Umpierre at Mar 5, 2012 at 9:17 pm

    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@googlegroups.com.
    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.
  • Colin Law at Mar 5, 2012 at 9:32 pm

    On 5 March 2012 21:17, Felipe Pieretti Umpierre 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@googlegroups.com.
    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.
  • Colin Law at Mar 5, 2012 at 9:36 pm

    On 5 March 2012 21:00, Felipe Pieretti Umpierre 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@googlegroups.com.
    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.
  • Felipe Pieretti Umpierre at Mar 5, 2012 at 11:29 pm
    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@googlegroups.com.
    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.
  • Eddie Lau (http://36613.me) at Mar 6, 2012 at 12:38 am
    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 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@googlegroups.com.
    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@googlegroups.com.
    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.
  • Colin Law at Mar 6, 2012 at 8:32 am
    On 5 March 2012 23:29, Felipe Pieretti Umpierre 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@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMar 5, '12 at 9:00p
activeMar 6, '12 at 8:32a
posts9
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase