我在其中一个视图中使用了表单助手,我希望用户从选项列表中进行选择。然后,我想将所选选项的id等效存储到我的数据库中。但是,每次我选择一个选项时,它的id都没有被存储,数据库只对这个属性说nil。
<%= f.label :"Team Against" %><br>
<%= f.select :opposing_team, options_for_select([['Team 1', 1], ['Team 2', 2], ['Team 3', 3]]) %><br>
例如,我的表格中有一列名为&#39; opposite_team&#39;当用户选择团队1时,我希望用值1更新opposition_team。目前我可以选择表单中的选项范围,但reflect_team值总是为零。
编辑:
def create
@league = League.find(params[:league_id])
@team = @league.teams.find(params[:team_id])
@fixture = @team.fixtures.create(fixture_params)
if @fixture.save
redirect_to league_team_path(:league_id => @league.id, :id => @team.id)
else
render 'new'
end
end
def new
@team = Team.find(params[:team_id])
@fixture = Fixture.new
end
这是灯具控制器的组成部分。 opposition_team是数据库中的整数值。
答案 0 :(得分:1)
这是一个常见问题,通常答案是Release notes错过了必需的密钥。 在你的控制器中,你最后有一个方法看起来像:
def fixture_params
params.require(:fixture).permit(:value, :other_value, :opposing_team)
end
如果是,请将/**
* This implementation uses HttpEngine to send requests and receive responses. This class may use
* multiple HttpEngines to follow redirects, authentication retries, etc. to retrieve the final
* response body.
*
* <h3>What does 'connected' mean?</h3> This class inherits a {@code connected} field from the
* superclass. That field is <strong>not</strong> used to indicate whether this URLConnection is
* currently connected. Instead, it indicates whether a connection has ever been attempted. Once a
* connection has been attempted, certain properties (request header fields, request method, etc.)
* are immutable.
*/
public class HttpURLConnectionImpl extends HttpURLConnection {
private String defaultUserAgent() {
String agent = System.getProperty("http.agent");
return agent != null ? Util.toHumanReadableAscii(agent) : Version.userAgent();
}
添加到密钥列表中。
System.getProperty("http.agent");