Skip to content

Commit

Permalink
miscellaneous tweaks and fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
manxingxing committed Aug 5, 2013
1 parent f5cb743 commit c9b7a7a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
18 changes: 7 additions & 11 deletions app/controllers/datasets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ def create # create dataset with only a title
def create_with_datafile
unless params[:datafile]
flash[:error] = "No data file given for upload"
redirect_to :back and return
redirect_back_or_default root_url and return
end

datafile = Datafile.new(params[:datafile])
unless datafile.save
flash[:error] = datafile.errors.full_messages.to_sentence
redirect_to :back and return
redirect_back_or_default root_url and return
end

attributes = datafile.general_metadata_hash
attributes.merge!(title: params[:title].squish.capitalize) if params[:title]
attributes.merge!(title: params[:title].squish) if params[:title]
@dataset = Dataset.new(attributes)
if @dataset.save
@dataset.add_datafile(datafile)
Expand All @@ -72,7 +72,7 @@ def create_with_datafile
else
datafile.destroy
flash[:error] = @dataset.errors.full_messages.to_sentence
redirect_to :back
redirect_back_or_default root_url
end
end

Expand Down Expand Up @@ -164,15 +164,11 @@ def show
end

def index
datasets = Dataset.all
response = Array.new
datasets.each do |ds|
response << { :id => ds.id, :title => ds.title }
end
datasets = Dataset.select("id, title")

respond_to do |format|
format.json { render :json=> response}
format.xml { render :xml=> response}
format.json { render :json => datasets }
format.xml { render :xml => datasets }
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def index
@tags = Dataset.tag_counts.where("name iLike ?", "%#{params[:q]}%").order("tags.name")
respond_to do |format|
format.html
format.json { render :json=> @tags.map(&:attributes)}
format.xml { render :xml=> @tags.map(&:attributes)}
format.json { render :json => @tags}
format.xml { render :xml => @tags.map(&:attributes) }
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def abstract_with_freeformats
f_strings = self.freeformats.collect do |f|
"File asset " + f.file_file_name + (f.description.blank? ? "" : (": " + f.description))
end
self.abstract + (f_strings.empty? ? "" : (" - " + f_strings.join(" - ")))
self.abstract.to_s + (f_strings.empty? ? "" : (" - " + f_strings.join(" - ")))
end

def download_status
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/party_foul.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# PartyFoul.configure do |config|
# config.blacklisted_exceptions = ['ActiveRecord::RecordNotFound', 'ActionController::RoutingError']
# config.blacklisted_exceptions = ['ActiveRecord::RecordNotFound', 'ActionController::RoutingError', 'AbstractController::ActionNotFound']
# config.oauth_token = CONFIG[:party_foul_github_oauth_token]
# config.endpoint = 'https://api.github.com'
# config.web_url = 'https://github.com'
Expand Down
14 changes: 14 additions & 0 deletions config/initializers/wrap_parameters.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Be sure to restart your server when you modify this file.
#
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.

# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json]
end

# Disable root element in JSON by default.
ActiveSupport.on_load(:active_record) do
self.include_root_in_json = false
end
Binary file not shown.

0 comments on commit c9b7a7a

Please sign in to comment.