Hi All,
I'm trying to override the update action in a controller because I already
have a customized action there. The problem is that activescaffold is still
trying to call its own update action. how can I fix this?
here's my controller :
class SearchesController < ApplicationController
SEARCH_DEFAULT_COLUMNS = [:title, :join_operator, :search_parameters,
:created_at, :updated_at]
skip_before_filter :fix_nested_attribute_params
layout 'no_left_nav'
before_filter :get_results
before_filter :get_anchor, :only => :show
before_filter :update_as_config
active_scaffold :search do |config|
config.create.link = false
config.search.link = false
config.list.columns = SEARCH_DEFAULT_COLUMNS
config.show.link.inline = false
config.update.link = false
config.label = "My Searches"
end
#you must pass either a search_id or a search_class in order to use this
action
def update
if params[:search_id]
@search = Search.find(params[:search_id])
elsif params[:id]
@search = Search.find(params[:id])
elsif params[:search_class]
@search =
@session_user.working_search(params[:search_class].classify.constantize)
end
@title = "Edit Search '#[email protected]? ? @search.title.titleize :
@search.search_class_name.titleize}'"
if params[:search]
@search.update_from_controller(params)
end
respond_to do |format|
format.html{redirect_to :back}
format.js {
render :update do |page|
page.replace "search_results", :partial =>
'searches/results', :object => @search.results(params)
end
}
end
end
private
def update_as_config
active_scaffold_config.label = "My #{params[:search_class_name] ?
params[:search_class_name] + " " : ''}Searches"
active_scaffold_config.list.columns << :search_class_name unless
params[:search_class_name]
end
def conditions_for_collection
"user_id = #{current_user.id} #{params[:search_class_name] ? "and
search_class_name = '#{params[:search_class_name]}'" : ""}"
end
def get_results
@results = @search.results(params)
end
#this pulls in a polymorphic item and sets it as the anchor.
#you should not pass multiple *_id params to the show action here
#because you will get unexpected behavior.
def get_anchor
params.each do |name, value|
if name =~ /(.+)_id$/
@anchor = $1.classify.constantize.find(value)
instance_variable_set("@#{$1}", @anchor)
end
end
nil
end
end
here's the request :
Processing SearchesController#update (for 127.0.0.1 at 2009-09-04 15:05:26)
[PUT]
Parameters: {"search"=>{"title"=>"", "join_operator"=>"OR", "save"=>"0"},
"search_parameters"=>{"512"=>{"characteristic_id"=>"146",
"selected_value"=>"", "selected_operator"=>"NOT BLANK"},
"242"=>{"characteristic_id"=>"25", "selected_value"=>["42"],
"selected_operator"=>"="}, "509"=>{"characteristic_id"=>"143",
"selected_value"=>"oeuoe", "selected_operator"=>"NOT BLANK"},
"510"=>{"characteristic_id"=>"144", "selected_value"=>"",
"selected_operator"=>"NOT BLANK"}, "511"=>{"characteristic_id"=>"145",
"selected_value"=>"", "selected_operator"=>"NOT BLANK"}}, "commit"=>"Find",
"authenticity_token"=>"tsAzpjdAnZdTFLZN+2OtTpUrFJ12V1m17dFjBN38sSs=",
"id"=>"1"}
here's the error :
NoMethodError in SearchesController#update
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
/storage/daisi/branches/demo/vendor/plugins/active_scaffold/lib/active_scaffold/attribute_params.rb:42:in
`update_record_from_params'
/storage/daisi/branches/demo/vendor/plugins/active_scaffold/lib/active_scaffold/actions/update.rb:81:in
`do_update'
/opt/ruby-enterprise-1.8.6-20090610/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in
`transaction'
/opt/ruby-enterprise-1.8.6-20090610/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:182:in
`transaction'
I just put the first couple of lines in the trace that show the
do_update being called. I didn't think the rest of it would be
relevant here
plz halp!
-C
/storage/daisi/branches/demo/vendor/plugins/active_scaffold/lib/active_scaffold/actions/update.rb:80:in
`do_update'
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---