【问题标题】:ruby on rails / routing-filter / form_for changes htmlruby on rails / routing-filter / form_for 更改 html
【发布时间】:2009-08-17 23:59:28
【问题描述】:

这个问题与路由过滤器有关。

我认为这是:

<% form_for :post, :url => {:action => "show"} do |f| %>

在浏览器中翻译成这样:

<form action="/en/posts/show" method="post">

更改 I18n.locale 后,例如

I18n.locale = :en

html变成:

<form action="/en/posts/72" method="post">

该操作不起作用,我收到此错误:

未知操作

对 72 没有任何响应。

当然,没有像 72 这样的动作。这个数字当然是 show 动作的输入。这是正确的邮政编号。所以如果我把这个地址 localhost:3000/en/posts/72 放到浏览器中,那么它给我的页面没有问题。

那么为什么它在表单中不起作用呢?

谢谢。

【问题讨论】:

  • 你为什么要发布到show action?
  • 为什么不呢?脚手架中的默认显示操作代码具有 @post = Post.find( params[:id],... 所以它应该采用 id 对吗?
  • POST 意味着发送数据以更新对象。 Show 检索一个对象进行显示,一个 GET 请求就足够了,而且是 RESTful 的。

标签: html ruby-on-rails routing filter form-for


【解决方案1】:

指定这样的方法:

<% form_for :goal, :url => { :action => 'show' }, :html => {:method => :put} do |f| %>

它对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    • 2011-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多