Herryanto S. wrote:
You can also try out:
return redirect_to(…)
You can avoid the “short-circuit”.
Hrm then I guess I’m having something substantially wrong, because I’m
always getting this error. So let’s track down what’s wrong…
The user types in the URL http://localhost:3000/admin/links/new
This routes to the controller Admin::LinksController and the action
“new” which is handled by a module I wrote once:
class Admin::LinksController < Admin::ApplicationController
include ActsAsManager
end
module ActsAsManager
…
def new
manage
end
…
end
This calls to the quite complex method “manage” (private one) - this
handles all the create/edit/update stuff that the normal scaffolds
would:
def manage
params[:id].nil? ?
self.model_obj = model_class.new :
self.model_obj = model_class.find(params[:id])
if request.get?
member_requests('CREATE', model_class) do
model_obj.attributes = params[model_obj_name]
end
elsif request.post?
model_obj.attributes = params[model_obj_name]
if model_obj.new_record?
member_requests!('CREATE', model_class) do
model_obj.creator = logged_in_member if
model_obj.respond_to?(‘creator=’)
model_obj.owner = logged_in_member if
model_obj.respond_to?(‘owner=’)
end
else
member_requests!(‘EDIT’, model_class)
end
if model_obj.save
if model_obj.new_record?
flash[:notice] = model_obj_name.capitalize + ' was
successfully created.’
redirect_to :action => :list and return
else
flash[:notice] = model_obj_name.capitalize + ’ was
successfully updated.’
redirect_to :action => :show, :id => model_obj and return
end
end
else
raise “Another method than GET or POST?! Woah!”
end
model_obj.new_record? ?
render(:action => :new) :
render(:action => :edit)
If the form contains a hidden field +lock_version+ then ActiveRecord
throws a StaleObjectError if its value has changed since the form was
called (positive locking).
TODO: Does this work anyhow anymore?!
rescue ActiveRecord::StaleObjectError
# TODO: Evaluate differences and add related errors
self.model_obj.errors.add(:base, “Object is stale!
#{self.model_obj.lock_version}:#{model_class.find_by_id(self.model_obj.id).lock_version}”)
render :action => :edit
end
So far, we’re getting to line where the member requests permission to
CREATE an item:
…
if request.get?
member_requests(‘CREATE’, model_class) do
…
which calls the method member_requests():
def member_requests(right_name, obj, options = {}, &block)
if
logged_in_member.has_system_right?(SystemRight.find_by_model_class_and_name(obj.to_s,
right_name))
yield if block_given?
else
render :file => “#{RAILS_ROOT}/public/404.html”, :layout => true,
:status => 404
end
end
And that’s where the DoubleRenderError is thrown! Anyone can see where
the problem is? I just want to render the 404.html file, nothing else…
No double rendering or stuff!
Thanks a lot
Josh