app/controllers/observations_controller.rb
# create project observations if a project was specified and project allows 
# auto-joining
create project observations if a project was specified and project allows
auto-joining
create project observations if a project was specified and project allows auto - joining
def create_project_observations
    return unless params[:project_id]
    @project = Project.find_by_id(params[:project_id])
    @project ||= Project.find(params[:project_id]) rescue nil
    return unless @project
    @project_user = current_user.project_users.find_or_create_by_project_id(@project.id)
    return unless @project_user && @project_user.valid?
    tracking_code = params[:tracking_code] if @project.tracking_code_allowed?(params[:tracking_code])
    errors = []
    @observations.each do |observation|
      next if observation.new_record?
      po = @project.project_observations.build(:observation => observation, :tracking_code => tracking_code)
      unless po.save
        errors = (errors + po.errors.full_messages).uniq
      end
    end
    if !errors.blank?
      if request.format.html?
        flash[:error] = t(:your_observations_couldnt_be_added_to_that_project, :errors => errors.to_sentence)
      else
        Rails.logger.error "[ERROR #{Time.now}] Failed to add #{@observations.size} obs to #{@project}: #{errors.to_sentence}"
      end
    end
  end
def create_project_observations return unless params [ :project_id ] @project = Project . find_by_id ( params [ :project_id ] ) @project ||= Project . find ( params [ :project_id ] ) rescue nil return unless @project @project_user = current_user . project_users . find_or_create_by_project_id ( @project . id ) return unless @project_user && @project_user . valid? tracking_code = params [ :tracking_code ] if @project . tracking_code_allowed? ( params [ :tracking_code ] ) errors = [ ] @observations . each do | observation | next if observation . new_record? po = @project . project_observations . build ( :observation => observation , :tracking_code => tracking_code ) unless po . save errors = ( errors + po . errors . full_messages ) . uniq end end if ! errors . blank? if request . format . html? flash [ :error ] = t ( :your_observations_couldnt_be_added_to_that_project , :errors => errors . to_sentence ) else Rails . logger . error "[ERROR #{Time.now}] Failed to add #{@observations.size} obs to #{@project}: #{errors.to_sentence}" end end end
create project observations if a project was specified and project allows
auto-joining
create project observations if a project was specified and project allows auto - joining