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
def In Place Editor and Collection Partials
posted_by :Amos, :on => 'September 2nd, 2007'
I've noticed a lot of individuals have been having problems with the in_place_editor function and using a collection partial. The problem comes down to an in_place_editor looking for an variable beginning with an @. So here is the quick fix.
The partial function:
<%= render :partial => "item", :collection => @items %>
Inside the Partial:
<%@item = item%> <%= in_place_editor_field :item, 'on_hand' %>
I know it is a bit of a hack, but it is a very quick fix. Happy Coding!