Forms 凤凰框架:资源在哪里';所有资源的默认表单@action属性来自?

Forms 凤凰框架:资源在哪里';所有资源的默认表单@action属性来自?,forms,phoenix-framework,Forms,Phoenix Framework,命令 mix phx.gen.html Blog Post posts title body:text 在其他文件中,为添加/编辑帖子表单生成模板form.html.eex,如下所示: <%= form_for @changeset, @action, fn f -> %> <%= if @changeset.action do %> <div class="alert alert-danger"> <p>Oops,

命令

mix phx.gen.html Blog Post posts title body:text
在其他文件中,为添加/编辑帖子表单生成模板form.html.eex,如下所示:

<%= form_for @changeset, @action, fn f -> %>
  <%= if @changeset.action do %>
    <div class="alert alert-danger">
      <p>Oops, something went wrong! Please check the errors below.</p>
    </div>
  <% end %>

  <div class="form-group">
    <%= label f, :title, class: "control-label" %>
    <%= text_input f, :title, class: "form-control" %>
    <%= error_tag f, :title %>
  </div>

  <div class="form-group">
    <%= label f, :body, class: "control-label" %>
    <%= textarea f, :body, class: "form-control" %>
    <%= error_tag f, :body %>
  </div>

  <div class="form-group">
    <%= submit "Submit", class: "btn btn-primary" %>
  </div>
<% end %>
我的路由器中有:locale范围

  scope "/:locale", MyProject.Web, as: :locale do
    pipe_through :browser
    get "/", PageController, :index
    resources "/posts", PostController        
  end
默认的@action不考虑作用域的区域设置块,将POST请求发送到/posts url,该url由MyProject.locale插件重定向到/de/posts作为GET请求(它使用函数Phoenix.Controller.redirect(to:…))。我希望表单将POST请求发送到本地化路径。 那么,我们可以在一个地方覆盖所有资源的@action参数,还是必须在渲染函数调用的每个控制器中提供它

render(conn, "new.html", changeset: changeset, action: action)

或者唯一的选择是更改所有资源的表单模板

“form_for function获取的@action参数在PostController中不存在,那么它从何而来?我找不到。”操作应该在
new.html.eex
edit.html.eex
等模板中,与
form.html.eex
@Dogbert位于同一文件夹中,谢谢!就在那里,我忘记了在PostController中,render函数获取新的.html模板,而不是form.html。现在很明显,我需要为每个资源更改new.html.eex和edit.html.eex。“form_for function获取@action参数,该参数在PostController中不存在,因此它来自何处?我找不到。”操作应该在
new.html.eex
edit.html.eex
中,etc模板与
form.html.eex
@Dogbert位于同一文件夹中,谢谢!就在那里,我忘记了在PostController中,render函数获取新的.html模板,而不是form.html。现在很清楚,我需要为每个资源更改new.html.eex和edit.html.eex。
render(conn, "new.html", changeset: changeset, action: action)