app/controllers/maps_controller.rb
#only allow editing by a user if the user owns it, or if and editor tries to edit it
only allow editing by a user if the user owns it, or if and editor tries to edit it
only allow editing by a user if the user owns it or if and editor tries to edit it
def check_if_map_is_editable
    if user_signed_in? and (current_user.own_this_map?(params[:id])  or current_user.has_role?("editor"))
      @map = Map.find(params[:id])
    elsif Map.find(params[:id]).owner.nil?
      @map = Map.find(params[:id])
    else
      flash[:notice] = t('maps.edit.cannot_edit_others')
      return redirect_to map_path
    end
  end
def check_if_map_is_editable if user_signed_in? and ( current_user . own_this_map? ( params [ :id ] ) or current_user . has_role? ( "editor" ) ) @map = Map . find ( params [ :id ] ) elsif Map . find ( params [ :id ] ) . owner . nil? @map = Map . find ( params [ :id ] ) else flash [ :notice ] = t ( 'maps.edit.cannot_edit_others' ) return redirect_to map_path end end
only allow editing by a user if the user owns it, or if and editor tries to edit it
only allow editing by a user if the user owns it or if and editor tries to edit it