This post originated from an RSS feed registered with Ruby Buzz
by Amos King.
Original Post: Ajax And Non-Ajax
Feed Title: DirtyInformation
Feed URL: http://feeds.feedburner.com/Dirtyinformation
Feed Description: Information about Ruby/Rails/JRuby/WebDevelpoment/whatever.
It took me a while to find out how to have a link work if a person has ajax enabled or not. So I thought I would share the solution.
#controller action
def new
@partial = params[:partial] || 'about'
respond_to do |want|
want.html {}
want.js { render :partial => @partial }
end
end
#link in view
<%= link_to_remote 'link', :url => formatted_new_session_url(:partial => 'partial_name', :format => 'js'), :update => div, :method => :get, :html => { :href => new_session_url(:partial => 'partial_name') } %>
#loading partial in view
<%= render :partial => @partial %>
This will allow you to reload the page_contents partial through ajax, but will reload the whole page with the correct partial if the browser doesn't support JavaScript.