diff --git a/app/controllers/locomotive/api/base_controller.rb b/app/controllers/locomotive/api/base_controller.rb index 72392136..1afc9d41 100644 --- a/app/controllers/locomotive/api/base_controller.rb +++ b/app/controllers/locomotive/api/base_controller.rb @@ -5,6 +5,10 @@ module Locomotive include Locomotive::Routing::SiteDispatcher include Locomotive::ActionController::LocaleHelpers + skip_before_filter :verify_authenticity_token + + skip_load_and_authorize_resource + before_filter :require_account before_filter :require_site @@ -13,10 +17,6 @@ module Locomotive # before_filter :validate_site_membership - skip_before_filter :verify_authenticity_token - - skip_load_and_authorize_resource - self.responder = Locomotive::ActionController::Responder # custom responder respond_to :json, :xml diff --git a/app/models/locomotive/content_type.rb b/app/models/locomotive/content_type.rb index ae2e92e9..457d3e27 100644 --- a/app/models/locomotive/content_type.rb +++ b/app/models/locomotive/content_type.rb @@ -78,6 +78,12 @@ module Locomotive self.class.class_name_to_content_type(class_name, self.site) end + def label_field_name=(value) + # mandatory if we allow the API to set the label field name without an id of the field + @new_label_field_name = value unless value.blank? + super(value) + end + # Retrieve from a class name the associated content type within the scope of a site. # If no content type is found, the method returns nil # @@ -111,7 +117,15 @@ module Locomotive def set_default_values self.order_by ||= 'created_at' - self.label_field_id = self.entries_custom_fields.first._id if self.label_field_id.blank? + + if @new_label_field_name.present? + self.label_field_id = self.entries_custom_fields.detect { |f| f.name == @new_label_field_name.underscore }._id + end + + if self.label_field_id.blank? + self.label_field_id = self.entries_custom_fields.first._id + end + field = self.entries_custom_fields.find(self.label_field_id) # the label field should always be required diff --git a/lib/locomotive/render.rb b/lib/locomotive/render.rb index e4935556..68f54658 100644 --- a/lib/locomotive/render.rb +++ b/lib/locomotive/render.rb @@ -17,10 +17,6 @@ module Locomotive output = @page.render(locomotive_context) - # puts "======================" - # puts output.inspect - # puts "======================" - self.prepare_and_set_response(output) end end