Я использую link_to и отправляю param вместе с ним.
<%= link_to "Create new environment", new_environment_path(:project => @project.id) %>
И пытаюсь использовать его в форме, как показано ниже.
<%= form.hidden_field :project_id, value: params[:project] %>
Но проблема в том, что rails получает запрос GET дважды. Первый раз с параметром проекта и второй без параметра.
07:31:09 rails.1 | 2020-02-06T07:31:09 [I|app|a82ba4dd] Started GET "/environments/new?project=1" for 192.168.121.1 at 2020-02-06 07:31:09 +0000
07:31:10 rails.1 | 2020-02-06T07:31:10 [I|app|cf3eb6ce] Rendered .vendor/ruby/2.5.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (906.3ms)
07:31:10 rails.1 | 2020-02-06T07:31:10 [I|app|a82ba4dd] Processing by EnvironmentsController#new as HTML
07:31:10 rails.1 | 2020-02-06T07:31:10 [I|app|a82ba4dd] Parameters: {"project"=>"1"}
07:31:10 rails.1 | 2020-02-06T07:31:10 [D|tax|a82ba4dd] Current location set to Default Location
07:31:10 rails.1 | 2020-02-06T07:31:10 [I|app|306b9b09] Started GET "/environments/new" for 192.168.121.1 at 2020-02-06 07:31:10 +0000
07:31:10 rails.1 | 2020-02-06T07:31:10 [I|app|306b9b09] Processing by EnvironmentsController#new as HTML
07:31:10 rails.1 | 2020-02-06T07:31:10 [D|tax|306b9b09] Current location set to Default Location
07:31:10 rails.1 | 2020-02-06T07:31:10 [D|tax|306b9b09] Current organization set to Default Organization
Из-за этой формы создается скрытый тег, в котором нет значения.
<input type="hidden" name="environment[project_id]">
Я ожидаю ниже
<input type="hidden" name="environment[project_id]" value="1">