嗨,这是我在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'
以下是我的错误,
<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行附近“无法将符号转换为字符串”。
答案 0 :(得分:1)
您可以使用form_tag
帮助程序。
<%= form_tag movies_path, method: :post do %>
...
<% end %>
建议阅读:http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-form_tag
答案 1 :(得分: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 %>
答案 2 :(得分:0)
此:
<form action = <%= "#{movies_path}"%> method = "post">
需要这样:
<form action <%= "#{movies_path}"%> method = "post">
在ERB输出之前无需放置等号。或者您应该使用form_tag
。