SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    970
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Inserting default value for first nested builder item in form

    So I've got a form and it's has some accepts_nested_attributes_for items in it.

    It's a project, task thing and what I'm wondering is if I can put the person creating the project as the leader (default first value for project_member) in the form itself or if this is something that should be handled on the create method of the controller.

    Here's the new action on the project controller
    Code Ruby:
      def new
        @project = Project.new
        3.times {@project.tasks.build}
        3.times {@project.project_members.build}
        3.times {@project.milestones.build}
     
        respond_to do |format|
          format.html {render :layout => "base"}
          format.js {render :layout => false}
        end
      end

    So basically, when building the project_members field, I'm wanting to be able to grab the person creating the form (based on session[:user]) and insert them as the first field in the list.

    Any help or pointers to some kind of tutorial is REALLY appreciated.
    your brain reacts in the same way whether you are
    looking at something or thinking about it...

  2. #2
    Team ********* Louis Simoneau's Avatar
    Join Date
    Sep 2009
    Location
    Melbourne, Australia
    Posts
    228
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I would definitely do that in the create method, not in the form itself. Just use whatever current_user method your authentication system is using.

  3. #3
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    970
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that's what I was thinking was the best idea.

    Thanks.
    your brain reacts in the same way whether you are
    looking at something or thinking about it...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •