English 中文(简体)
• 如何节省铁路的相关物体
原标题:How do i save an associated Object in Rails / Active Record

Lets say i have two models: Team --1---n--> Player In Words: A Team can have many Players. A Player belongs to a Team.

On the page that shows the Team-Data i want to place a link create Player .

在运动员控制员中,我如何创建运动员,使其与监察组有关系,在什么地方把创造者的联系放在谁?

我必须

1.通过监察组-ID,创建运动员控制员和

<>strong>2.上调监察组,利用监察组-ID,然后看小组。

3. something like this: @new_player = @team.players.build(...)

Can I use one of the resource routes for the create Player link?

问题回答

如果通过单独形式增加团队和参与者:

你可以包括团队——以新参与者的形式进行,或者在团队范围内向参与者指明路线,并将团队从“夜总会”栏目(<:team_id]<>。

Nested players route:

    resources :teams do
      resources :players
    end

3. 在你的团队/how(小组详细网页)中,建立运动员联系:

    <%= link_to  Create Player , new_team_player_path(@team) %>

In the players form:

    <% form_for [@team, @player] do |f| %>
    <!-- your form here -->
    <%- end -%>

在运动员控制员中:

    def new
      @team = Team.find params[:team_id]
      @player = Player.new
    end

    def create
      @player = Player.new params[:player]
      @player.team_id = params[:team_id] # => if just grabbing the id from the url params
      if @player.save
        # flash and redirect
      else
        # show form again
      end
    end

否则,见“Antoine”提到的“nes脏特性”的铁路,以一个形式说明新的团队和参与者的详细情况。 (我认为,你回顾的是第一个选择,有两种形式,但我可以走。)

关于冻结资源路线的更多信息,见Rails Routing Guide。 了解你的申请中有哪些路线,从指挥线上看,操作rake Line





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签