开发者

how to implement an toggle functionality for update link

currently i have an link as mentioned in below format

<%= link_to_if_authorized(l(:button_update), {:controller => 'issues', :action => 'edit', :id => @issue }, :onclick => 'showAndScrollTo("update", "notes"); return false;', :class => 'icon icon-edit', :accesskey => accesskey(:edit)) %>

i would like to apply toggle functionality on update could anyone开发者_Python百科 please help me.


There are numerous possibilities to achieve a toggle button. You may choose to change the JavaScript function your button executes, or the function may toggle the Rails action to call. I personally would go for a Rails action that knows how to toggle itself:

def toggle_action
  @model = Model.find param[:id]
  if @model.active?
    @model.active = false
    render :js => "alert('Active!');"
  else
    @model.active = true
    render :js => "alert('Inactive!');"
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜