gpt4 book ai didi

ruby-on-rails - 将 Rails 2 路由转换为 Rails 3

转载 作者:行者123 更新时间:2023-12-04 06:12:26 25 4
gpt4 key购买 nike

就像我昨天的第一个问题一样,我还在做 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com