English 中文(简体)
Rails:基本的Ajax问题! - 我正在寻找关于列表简单添加和编辑的示例代码
原标题:Rails: basic Ajax question! - I m looking for example code about simple adding and editing for list

我使用 ruby script/generate scaffold subject name:string desc:string 命令创建了一个简单的 Rails 页面。

现在,我可以以RESTful的方式添加、编辑和删除主题。

What I like to do is changing above behavior as Ajax way. Everything can be done in index page. For example...this is the page throw the browser~

屏幕1

Listing subjects
name  desc
test1 test1 show edit destroy
test2 test2 show edit destroy
[___] [___] create

如果您点击编辑链接,页面将会像下面这样转换

屏幕2

Listing subjects
name    desc
[test1] [test1] update             <-------- this !!! text_field !
test2   test2   show edit destroy

And you can change name and desc. After change the values, clicking update link will update it and browser will display similar page with 屏幕1

此外,您可以通过在列表底部填写空白文本字段并点击创建链接来添加新主题。它会立即应用。

我试图找出这个问题的答案,但是Railscasts和其他一些网页都没有帮助。 :(

Do anybody know where the sample code for this is or please write simple one !!! I really appreciate it if you do so...........

问题回答

将要动态更新的每一行都用form_remote_tag封装起来。当点击更新按钮时,表单字段将通过ajax发送到服务器。

<% form_remote_tag :action => :update do %>
  <%= text_field_tag :name, @name %>
  <%= text_field_tag :desc, @desc %>
  <%= submit_tag "Update" %>
<% end %>

然后在服务器端执行以下操作:

def update
  #do normal update stuff

  #send RJS back to the user that we did something.
  render :update do |page|
    page.alert "item updated!"
  end
end




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签