开发者

Highlighting the link_to_remote link

开发者 https://www.devze.com 2022-12-27 09:01 出处:网络
Hi i have the rails application. when i call the home controller i have index action . in the index.html.erb .ihave some link_to_remote links.

Hi i have the rails application. when i call the home controller i have index action . in the index.html.erb .i have some link_to_remote links.

<li><%=link_to_remote "Example",
  :update =>'view',
  :url =>{:controller => 'home',:action => 'bank'},
  :method => :post,
  :html =>{:id =>"cb"},
  :with => "'choose=' +encodeURIComponent('value')" %></li>


<li><%=link_to_remote "Test",
  :update =>'view',
  :url =>{:controller => 'home',:action => 'bank'},
  :method => :post,
  :html => { :id =>'cb1'},
  :with => "'choose=' +encodeURIComponent('value开发者_开发技巧')" %></li>

After clicking the "Example" and "Test" option the respective div got updated .... i want to highlighting the options after user click happened... consider If "Example" clicked i want to highlight "Example" option background...

I tried with current_page? rails helper method, :complete attribute of link_to_remote but no luck can any one please suggest me on this. ... Thanks in advance


there are params[:controller] and params[:action] that help you to know which action is current.


<div id='example_link'>
  <%= link_to_remote "Example",
      :update =>'view',
      :url =>{:controller => 'home',:action => 'bank'},
      :method => :post,
      :html =>{:id =>"cb"},
      :with => "'choose=' +encodeURIComponent('value')" %>
</div>

in your home controller

def bank
  # your code
  render :update do |page|
    page << "$('#example_link').addClass('highlighted')"
  end
end

in css

.highlighted{
  background-color: yellow;
}
0

精彩评论

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