me

def Ajax And Non-Ajax

posted_by :Amos, :on => 'October 24th, 2008'

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
<p id="page_contents" class="public_main">
  <%= render :partial => @partial %>
</p>

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.

end

end