0

谢谢你的时间!

我得到路线routes.rb

get "loadreport/test"
post "loadreport/update"

控制器中的test函数loadreport是一个空函数:

def test
end

test.html.erb 包含:

<form action="/loadreport/update?method=post" class="button_to" method="post">
  <div>
    <input type="submit" value="Update" />
    <textarea cols="30" id="post_body" name="comments" rows="5" maxlength=200>

    </textarea>
  </div>
</form>

update函数将更新数据库:

def update
  some_database.update(params[:comments])
end

现在,当我单击Update buttonin 时test.html.erb,它会调用/loadreport/update并跳转到update.html.erb. 由于update.html.erb不存在,服务器会给我如下错误:Template is missing ... blah ...

我想要实现的是:当我点击Update buttonin 时test.html.erb,它会简单地调用/loadreport/update更新数据库,然后弹出一个消息框,上面写着“更新成功!”,而不是跳转到另一个页面。

如何更改我的代码以实现这一目标?谁能给我一些关于这个主题的想法或一些链接。谢谢!

4

1 回答 1

1

您可以发布 Ajax 帖子并获得回报并显示警报。试试 jQuery。

或尝试:

def update
   some_database.update(params[:comments])
   redirect_to :test
end

这将重定向到上一页。

于 2012-12-04T12:49:34.823 回答