Skip to content

Instantly share code, notes, and snippets.

@arturdent
Created December 5, 2012 07:14
Show Gist options
  • Save arturdent/4213351 to your computer and use it in GitHub Desktop.
Save arturdent/4213351 to your computer and use it in GitHub Desktop.
1) Transport::CardsController should creates card
Failure/Error: response.code.should == '200'
expected: "200"
got: "500" (using ==)
# ./spec/requests/transport/cards_spec.rb:34:in `block (2 levels) in <top (required)>'
вот такой фильтр в transport_controller
before_filter(:only => :create) do
begin
root_key = self.class.model.name.underscore.gsub('/', '_')
unless params[root_key].blank?
@resource = self.class.model.send(:"find_or_initialize_by_#{self.class.key}", params[root_key][self.class.key])
@resource.assign_attributes(params[root_key])
else
render_error "Root attribute #{root_key} not found."
end
rescue ActiveRecord::UnknownAttributeError
render_error "Missing attribute: #{$!.to_s}"
end
end
....
def render_error(string)
render :json => {:system_error => string}, :status => 500
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment