如何传递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>
例如,用户可以输入&#34;运行5英里&#34;进入text_field
。如何传递link_to
?
答案 0 :(得分:0)
知道了!
<%= 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>