in_place_editor用法

今天想做一个在线编辑的东西,翻遍了图书,讲的都是用in_place_edit_for在controller里面添加一个方法,然后在相应的视图里面添加一个in_place_editor_field的help方法,在实现现场编辑功能,但是如果需要实现现场编辑功能的时候,并没有配套的controller怎么办……查询了Rails的类库,发现除了上述提到的2个以外,还有一个in_place_editor方法,直接在视图里面添加,不需要另外添加什么方法,直接指定需要现场编辑的HTML元素的DOM ID即可。

 

以下摘自Rails1.2.6的类库:

in_place_editor(field_id, options = {})

DEPRECATION WARNING: This method will become a separate plugin when Rails 2.0 ships.

Makes an HTML element specified by the DOM ID field_id become an in-place editor of a property.

A form is automatically created and displayed when the user clicks the element, something like this:

  <form id="myElement-in-place-edit-form" target="specified url">
    <input name="value" text="The content of myElement"/>
    <input type="submit" value="ok"/>
    <a οnclick="javascript to cancel the editing">cancel</a>
  </form>

The form is serialized and sent to the server using an AJAX call, the action on the server should process the value and return the updated value in the body of the reponse. The element will automatically be updated with the changed value (as returned from the server).

Required options are:

:url:Specifies the url where the updated value should be sent after the user presses "ok".

Addtional options are:

:rows:Number of rows (more than 1 will use a TEXTAREA)
:cols:Number of characters the text input should span (works for both INPUT and TEXTAREA)
:size:Synonym for :cols when using a single line text input.
:cancel_text:The text on the cancel link. (default: "cancel")
:save_text:The text on the save link. (default: "ok")
:loading_text:The text to display while the data is being loaded from the server (default: "Loading…")
:saving_text:The text to display when submitting to the server (default: "Saving…")
:external_control:The id of an external control used to enter edit mode.
:load_text_url:URL where initial value of editor (content) is retrieved.
:options:Pass through options to the AJAX call (see prototype’s Ajax.Updater)
:with:JavaScript snippet that should return what is to be sent in the AJAX call, form is an implicit parameter
:script:Instructs the in-place editor to evaluate the remote JavaScript response (default: false)

:click_to_edit_text::The text shown during mouseover the editable text (default: "Click to edit")

 

哎……早知道就自己查查类库了,省得一开始还弄的那么麻烦,还想着单独建立一个controller……

在view里面:

<span id="xxx"><%= 需要现场编辑的内容%></span>
<%= in_place_editor "xxx",:url=>{用来处理提交数据的方法}%>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值