あなたが達成しようとしていることを100%確信しているわけではありませんが、おそらくクエリーストリングを使用することができます。docs on link_toにはあなたがそうする方法の例があります。あなたの例ではそう
このような何か:あなたは切り替えたい最初のスニペットでli
上の属性によって
<ul class="dropdown-menu">
<% @sidebar_categories.each do |category| %>
<li data-toggle="modal" data-target="#howtoFormModal">
<%= link_to category.title, some_path(id: category.id) %>
</li>
<% end %>
</ul>
# Which has an output like this
<a href="/some-path?id=1">Category Title</a>
そして...
<%= simple_form_for @howto, url: category_howtos_path(params[:id]) do |f| %>
#whatever here...
<% end %>
編集
クリックでモーダルになり、次にsimple_form_for
URLパラメータに切り替えられたモーダルのIDを持ちます。問題は、category_howtos_path
がルビのページ読み込み前に評価されていることです。したがって、そのURLを変更したい場合は、javascriptを使用することができます。だから多分javascriptでモーダルをロードし、イベントコールバックを持っています。 JSと
EDITは
スニペットええ、私はすでに試みたが、多分私はそれを間違った方法をしました。
$('#howtoFormModal').on('show.bs.modal', function (e) {
//but I think that the JS will give a lot due to the rails loop
var categoryId = $("#li-id").data('id')
// just to show the id on the modal
$('#howtoFormModalLabel').val(categoryId);
});
あなたは)あなたがそう
$('#howtoFormModal').on('show.bs.modal', function (e) {
// The categoryId from here needs to be from the clicked on element
var categoryId = $(e.relatedTarget).data('id')
// just to show the id on the modal
$('#howtoFormModalLabel').val(categoryId);
}をクリックした要素のidを取得したいと思います。
以前は、別のページのフォームであったからです。しかし今はモーダルの中にあるので、別のページに行く必要はもうありません。あなたの提案に感謝 – NeimadTL
ああ私は私の答えを更新しました –
私はおそらく助けることができるjsコードであなたの質問を更新する場合は? –