Rails教程Ch10,练习10.1.1 q2 - 如何渲染表单但指向不同的URL?

时间:2016-10-12 08:10:14

标签: ruby-on-rails

来自Rails教程Ch 10.1.1,q2:https://www.railstutorial.org/book/updating_and_deleting_users

我已经重构了我的注册表单并编辑了用户#new和用户#编辑表单部分:

<%= form_for(@user) do |f| %>

  <%= render 'shared/error_messages', object: @user %>

  <%= f.label :name %>
  <%= f.text_field :name, class: 'form-control' %>

  <%= f.label :email %>
  <%= f.email_field :email, class: 'form-control' %>

  <%= f.label :password %>
  <%= f.password_field :password, class: 'form-control' %>

  <%= f.label :password_confirmation, "Confirmation" %>
  <%= f.password_field :password_confirmation, class: 'form-control' %>

  <%= f.submit yield(:button_text), class: 'btn btn-primary' %>
<% end %>

在users / new.html.erb和users / edit.html.erb中,我只需添加代码,

<%= render 'form' %>

问题是,我的用户#create被路由到/ signup

那么如何让users / new.html.erb中的表单路由到signup_path?

我试过

<%= render 'form', url: signup_path %>

但似乎没有效果?

1 个答案:

答案 0 :(得分:1)

你需要提供url来形成帮助:

SELECT t2.col2, REPLACE(REPLACE(t2.col2,t1.col1,REPLACE(t1.col1, '-', '_')),t3.col1,REPLACE(t3.col1, '-', '_')) 
FROM table_2 t2
JOIN table_1 t1 ON t2.col2 like '%' +t1.col1+'%' AND t1.col1 LIKE '%-%'
LEFT JOIN table_1 t3 ON t3.col1 <> t1.col1 AND t2.col2 LIKE '%'+t3.col1+'%' AND t3.col1 LIKE '%-%'
WHERE t2.col2 LIKE '%-%'