如何将url传递给partial / form?

时间:2015-05-09 10:40:49

标签: ruby-on-rails ruby ruby-on-rails-4

我想将网址传递给一个部分的表单。但是,当前设置会生成错误消息:

CREATE TABLE [dbo].[Curse]
(
    [IDCursa] NUMERIC (18, 0) NOT NULL PRIMARY KEY,
    [IDTraseu] NUMERIC (18, 0) NOT NULL, 
    [Data] TIMESTAMP NOT NULL, 
    [IDCompanie] NUMERIC (18, 0) NOT NULL, 
    [NrLocuri] NUMERIC (18, 0) NOT NULL, 
    [IDAutocar] NUMERIC (18, 0) NOT NULL, 

    CONSTRAINT [FK_Curse_Trasee] 
       FOREIGN KEY ([IDTraseu]) 
       REFERENCES [Trasee]([IDTraseu]), 
    CONSTRAINT [FK_Curse_Companii] 
       FOREIGN KEY ([IDCompanie]) 
       REFERENCES [Companii]([IDCompanie]), 
    CONSTRAINT [FK_Curse_Autocare] 
       FOREIGN KEY ([IDAutocar]) 
       REFERENCES [Autocare]([IDAutocar])
)

错误突出显示部分/表单的第3行SyntaxError in OrganizationsController#new syntax error, unexpected keyword_do, expecting keyword_end ...or(@organization), url="url" do |f| @output_buffer.safe_appe... ...

两个视图都使用partial / form,为此包括:

<%= form_for(@organization), url="url" do |f| %>

路线包括:

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

1 个答案:

答案 0 :(得分:1)

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”字符串

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