开发者

Rails AJAX ERB View Question link_to_remote

Rals 3.0

My question is using link_to_remote to make an ajax call.

2.3.8 Ajax call

<%= link_to_remote image_tag("../images/services_button.jpg", :mouseover => 
    "../images/services_button_over.jpg"), :url =>{:controller => :dashboard, :action => :service} %>

Current View -

<% link_to_remote view_path do %>
            About Us<span>Who we are</span>
<% end %>

How do I go about turning my current view code into an ajax call ? I've tried something like this ...

<% link_to_remote "hello", :url=>{:controller=>:sae,:action=>:bam} do %>
            About Us<span>Who we are</span>
      <% end %>

Thanks for your help in advance.

Trying to do basic...basic.. UJS.

Very simple AJAX call to make a div go up. Though it's not working. Trying to transition from 2.3.8 to 3.0. Any help is greatly appreciated. I've googled, though I'm not able to make any sense of the jargon. :( Thanks in ad开发者_运维知识库vance

View:

<div class="test">
  Whompa
</div>
<%= link_to 'Blind-Up', :controller=>:home,:actions=>:test, :remote =>true %>

Controller:

  def test
    render :update do |page|
      page[:test].visual_effect :blind_up
    end
  end


The Rails 3 syntax is now <%= link_to "hello", :remote => true %>. There's quite a few blog posts/tutorials online about making ajax calls with the new syntax - I'd recommend http://code.alexreisner.com/articles/link-to-remote-with-ujs.html, http://blog.solnic.eu/2009/09/08/unobtrusive-javascript-helpers-in-rails-3 and http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/ as a good starting point. Hope that helps!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜