如何将 url 传递给部分/表单? [英] How to pass url to partial/form?

查看:69
本文介绍了如何将 url 传递给部分/表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 url 传递给一个表单,它是部分表单.但是,当前设置会生成一条错误消息:

I would like to pass the url to a form, which is in a partial. However, the current setup generates an error message:

SyntaxError in OrganizationsController#new
syntax error, unexpected keyword_do, expecting keyword_end ...or(@organization), url="url" do |f| @output_buffer.safe_appe... ... 

错误突出显示部分/表单的第三行,即 <%= form_for(@organization), url="url" do |f|%>

The error highlights the 3rd line of the partial/form which is <%= form_for(@organization), url="url" do |f| %>

两个视图都使用了部分/表单,为此包括:

Two views both use the partial/form, and to this end include:

## View1:
<%= render 'registrationform', local:{url: signup_checkout_path} %>
## View2 (url should point to `def create` in organizations controller):
<%= render 'registrationform', local:{url: organizations_path} %>

路线包括:

resources :organizations
post 'signup/register'    => 'organizations#checkout', as: 'signup_checkout'

部分注册表包括:

<% if local_assigns.has_key? :url %>
  <%= form_for(@organization), url="url" do |f| %>
  ...
<% else %>
  ????
<% end %>

Def new 在控制器中:

def new
  if (logged_in?)
    flash[:danger] = "You're already logged in"
    redirect_to root_url
  end
  @organization = Organization.new
  @member = @organization.members.build
end

推荐答案

local 更改为 locals

## View1:
<%= render "registrationform", { url: signup_checkout_path } %>
## View2 (url should point to `def create` in organizations controller):
<%= render "registrationform", { url: organizations_path } %>

并传递url变量而不是url"字符串

And pass url variable not "url" string

<% if local_assigns.has_key? :url %>
   <%= form_for @organization, url: url do |f| %>
   ...
<% else %>
   ????
<% end %>

这篇关于如何将 url 传递给部分/表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆