[英]link_to populated with what was entered in text_field?
如何通過link_to
傳遞到在text_field
中輸入的內容?
new.html.erb
<%= f.text_field :name, class: 'form-control', id: "challenge-action-home",maxlength: @maximum_length, placeholder: 'Enter Challenge' %>
<%= link_to create_challenge_path(challenge: {name: ???}), data: { modal: true } do %>
<span class="glyphicon glyphicon-plus"></span>
<% end %>
<script>
# Maybe use javascript?
</script>
例如,用戶可以在text_field
輸入“ Run 5 Miles”。 如何通過link_to
傳遞?
得到它了!
<%= f.text_field :name, class: "name_field", id: "challenge-name", maxlength: @maximum_length, placeholder: 'Enter Challenge' %>
<%= link_to "Save", create_challenge_path(challenge: {name: @challenge.name}), data: { modal: true }, class: "create_challenge_link" %>
<script>
$(".create_challenge_link").click(function() {
$(this).attr("href", function() {
return this.href + $('.name_field').val();
});
});
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.