1

嗨,这是我在 HAML 中的 form_tag,当我将其转换为 erb 时出现错误,

%h2 Create New Movie

= form_tag movies_path, :method => :post do

= label :movie, :title, 'Title'
= text_field :movie, :title

= label :movie, :rating, 'Rating'
= select :movie, :rating, ['G','PG','PG-13','R','NC-17']

= label :movie, :release_date, 'Released On'
= date_select :movie, :release_date

= submit_tag 'Save Changes'

下面是我的erb,

<h2> Create New Movie </h2>

<form action = <%= "#{movies_path}"%> method = "post"> 

 <%= label :movie, :title, 'Title' %>
 <%= text_field :movie, :title %>

 <%= label :movie, :rating, 'Rating' %>
 <%= select :movie, :rating, ['G','PG','PG-13','R','NC-17'] %>

 <%= label :movie, :release_date, 'Released On' %>
 <%= date_select :movie, :release_date %>

 <%= submit_tag 'Save Changes' %>
</form>

我在第 12 行附近收到“无法将符号转换为字符串”。

4

3 回答 3

1

最好的方法是使用 RESTful 资源和表单对象:

<%= form_for @movie do |f| %>
  <%= f.label :title %>
  <%= f.text_field :title %>

  <%= f.label :rating %>
  <%= f.select :rating, ['G','PG','PG-13','R','NC-17'] %>

  <%= f.label :release_date, 'Released On' %>
  <%= f.date_select :release_date %>

  <%= f.submit 'Save Changes' %>

<% end %>
于 2013-08-13T19:50:28.533 回答
1

您可以使用form_tag助手。

<%= form_tag movies_path, method: :post do %>
...
<% end %>

建议阅读:http ://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-form_tag

于 2013-08-13T19:40:24.393 回答
0

这个:

<form action = <%= "#{movies_path}"%> method = "post">

需要是这样的:

<form action <%= "#{movies_path}"%> method = "post">

在 ERB 中发生输出之前无需放置等号。或者你应该使用form_tag.

于 2013-08-13T19:40:17.830 回答