app/controllers/muck/activities_controller.rb in muck-activities-0.1.11 vs app/controllers/muck/activities_controller.rb in muck-activities-0.1.12
- old
+ new
@@ -22,11 +22,10 @@
def create
@activity = @parent.activities.build(params[:activity])
@activity.source = @parent
@activity.content.gsub!(@parent.display_name, '')
@parent.save!
-
@activity_html = get_activity_html(@activity)
if @activity.template == 'status_update'
@status_html = get_status_html(@parent)
else
@status_html = ''
@@ -75,10 +74,15 @@
format.js do
render :update do |page|
page_alert(page, message)
end
end
+ format.json do
+ render :json => { :success => false,
+ :exception => ex,
+ :message => t("muck.activities.create_error", :error => errors) }
+ end
end
end
def destroy
@@ -94,14 +98,18 @@
@new_status = get_status_html(@activities_object)
render(:update) do |page|
page << "jQuery('##{@activity.dom_id}').fadeOut();"
page.replace_html 'current-status', @new_status if @new_status
end
+ else
+ render(:update) do |page|
+ page << "jQuery('##{@activity.dom_id}').fadeOut();"
+ end
end
end
format.json do
- @new_status = get_status_html(@activities_object)
+ @new_status = get_status_html(@activities_object) if @activity.is_status_update
render :json => { :success => true,
:is_status_update => @activity.is_status_update,
:html => @new_status,
:message => t("muck.activities.item_removed") }
end
@@ -121,17 +129,28 @@
end
protected
def get_status_html(activity)
- @template.template_format = :html
- render_to_string(:partial => 'activities/current_status', :locals => {:activities_object => activity})
+ render_as_html do
+ render_to_string(:partial => 'activities/current_status', :locals => {:activities_object => activity})
+ end
end
def get_activity_html(activity)
- render_to_string(:partial => "activity_templates/#{activity.template}", :locals => { :activity => activity })
+ render_as_html do
+ render_to_string(:partial => "activity_templates/#{activity.template}", :locals => { :activity => activity })
+ end
end
+ def render_as_html
+ last_template_format = @template.template_format
+ @template.template_format = :html
+ result = yield
+ @template.template_format = last_template_format
+ result
+ end
+
def find_parent
@klass = params[:parent_type].to_s.capitalize.constantize
@parent = @klass.find(params[:parent_id])
end
\ No newline at end of file