Skip to content

Commit

Permalink
Improved grid.js for update/create calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed May 9, 2012
1 parent 8de7f9f commit 7950f05
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 69 deletions.
19 changes: 17 additions & 2 deletions app/controllers/nodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,20 @@ def create
format.html {
redirect_to params[:redir] || zen_path(@node, :mode => params[:mode], :new => 'true')
}
format.js
format.js do
if params[:zjs]
attrs = {'id' => @node.zip}
params[:node].each do |k,v|
v = @node.zafu_eval(k, params[:opts])
attrs[k] = v
end
puts attrs.to_json
render :json => attrs.to_json, :status => :created
end
end
format.xml { render :xml => @node.to_xml(:root => 'node'), :status => :created, :location => node_url(@node) }
else
# ERROR
format.html do
flash[:error] = error_messages_for('node', :object => @node)
if request.referer
Expand All @@ -247,7 +258,11 @@ def create
raise ActiveRecord::RecordNotFound
end
end
format.js
format.js do
if params[:zjs]
render :json => @node.errors, :status => :unprocessable_entity
end
end
format.xml { render :xml => @node.errors, :status => :unprocessable_entity }
end
end
Expand Down

0 comments on commit 7950f05

Please sign in to comment.