2
부분적으로 양식을 호출하는 페이지에 따라 다른 경로로 설정할 수있는 양식 부분에서 동적 경로를 사용하는 방법은 무엇입니까?부분적인 형태의 동적 경로?
예를 들어, 내 _form.html.erb 파일에, 하단에 동적으로 그것을 호출하는 페이지의 메신저에 따라 '취소'경로를 변경할 수 있도록하고 싶습니다 :
<div class="row">
<div class="col-md-6 offset-md-3">
<%= form_for(@chef, :html => {class: "form-horizontal", role: "form" }) do |f| %>
<div class="form-group">
<%= f.label :chefname %>
<%= f.text_field :chefname, class: "form-control",
placeholder: "Chef Name",
autofocus: true %>
</div>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, class: "form-control",
placeholder: "Email" %>
</div>
<div class="form-group">
<%= f.label :password %>
<%= f.password_field :password, class: "form-control",
placeholder: "Must be at least 5 characters" %>
</div>
<div class="form-group">
<%= f.label :password_confrimation, "Confirm Password" %>
<%= f.password_field :password_confrimation, class: "form-control",
placeholder: "Confirm Password" %>
</div>
<div class="form-group">
<%= f.submit "#{action} Account", class: "btn btn-primary" %>
</div>
<% end %>
<%= link_to "Cancel", cancel %>
<hr>
<% if logged_in? && (current_chef == @chef || current_chef.admin?) %>
<%= link_to "Delete Account", chef_path(@chef), method: :delete,
class: "btn btn-sm btn-outline-danger",
data: { confirm: "Are you sure you want to delete this account and all corresponding recipes?" } %>
<% end %>
</div>
</div>
그런 다음 new.html.erb에서 내가 호출하는 곳에서 '취소'를 경로로 설정하려고 시도합니다.
<%= render "form", action: "Create", cancel: root_path %>
이 작업을 수행하는 올바른 방법은 무엇입니까? 그것은 내 브라우저에서 작동하는 것,하지만 내 테스트에서 나는 정의되지 않은 지역 변수 또는 메서드 '취소'를 얻을.
ActionView::Template::Error: undefined local variable or method `cancel' for #<#<Class:0x00000001da1e38>:0x0000000322cf10>