就像我昨天的第一个问题一样,我仍在做 that tutorial .
我遇到了另一个有关 Rails 2/Rails 3 路由差异的问题。
所以我的问题是:你如何“翻译”这个:
<%= form_remote_tag(:controller => "posts", :action => "create") do %>
到 Rails 3 路由?
编辑:这是我得到的错误代码:
Showing C:/Users/Lunasea/Web-Site/Standart/app/views/posts/_message_form.html.erb where line #5 raised:
C:/Users/Lunasea/Web-Site/Standart/app/views/posts/_message_form.html.erb:5: syntax error, unexpected tASSOC, expecting '}'
...pend= form_tag {:controller => "posts", :action => "create"...
C:/Users/Lunasea/Web-Site/Standart/app/views/posts/_message_form.html.erb:5: syntax error, unexpected ',', expecting '}'
...rm_tag {:controller => "posts", :action => "create"}, :remot...
C:/Users/Lunasea/Web-Site/Standart/app/views/posts/_message_form.html.erb:5: syntax error, unexpected tASSOC, expecting keyword_end
...action => "create"}, :remote => true do @output_buffer.safe_...
C:/Users/Lunasea/Web-Site/Standart/app/views/posts/_message_form.html.erb:12: syntax error, unexpected keyword_ensure, expecting keyword_end
C:/Users/Lunasea/Web-Site/Standart/app/views/posts/_message_form.html.erb:14: syntax error, unexpected $end, expecting keyword_end
_message_form.html.erb
的内容:
<% if logged_in? %>
<!--<% form_for product, :url => {:action => 'add_to_cart', :id => product.id}, :remote => true do %>-->
<!--<%= form_remote_tag(:controller => "posts", :action => "create") do %>-->
<%= form_for{:controller => "posts", :action => "create"}, :remote => true do %>
<%= label_tag(:message, "What are you doing?") %><br />
<%= text_area_tag(:message, nil, :size => "60x2") %><br />
<%= submit_tag("Update") %>
<% end %>
<% end %>
最佳答案
您可以使用 form_tag 并将 :remote => true
传递给它...
form_tag :url => {:controller => 'posts', :action => 'create'}, :remote => true
(确保您已包含 jQuery UJS 或等效的 Prototype 库,因为 Rails 不再像以前那样包含 javascript 内联。)
关于ruby-on-rails - 将 Rails 2 路线转换为 Rails 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7626546/