How to pass url to partial/form?

你说的曾经没有我的故事 提交于 2020-01-17 03:01:09

问题


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... ... 

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} %>

Routes includes:

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

And the partial registrationform includes:

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

Def new in the controller:

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

回答1:


Change local to locals

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

And pass url variable not "url" string

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


来源:https://stackoverflow.com/questions/30138927/how-to-pass-url-to-partial-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!