ProfilesController#show中的NoMethodError

时间:2015-04-11 20:11:28

标签: javascript ruby-on-rails ruby angularjs

我正在处理角度和轨道,我似乎无法在应用程序内部运行角度应用程序。我正在使用Ruby 2.1.1和Rails 4.1

刚刚提出这个错误,我认为我很接近搞清楚: enter image description here



angular.module('Waiting', [
        'ngRoute',
        'ng-rails-csrf',
        'templates'
    ]).config(function ($routeProvider, $locationProvider) {
        $routeProvider
            .when('/api/parties/:partiesId', {
                templateUrl: '../templates/wait.html',
                controller: 'WaitCtrl'
            });
        $locationProvider.html5Mode(true);
    });






angular.module('Waiting')
    .controller('WaitCtrl', [ '$scope', '$http', '$timeout', 'PartyService', function ($scope, $http, $timeout, PartyService) {
    		
    		$scope.init = function(){
	        $scope.partyCount = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10+'];
	        $scope.parties = [];
            $scope.formVisible = false;
          $scope.alerts = {};
          $scope.search = {
          };

	        PartyService.fetchParties()
	        	.success($scope.partiesReceived)
	       	.error($scope.partiesFailed)

    			
    		};

            $scope.oscillateForm = function(){
                $scope.formVisible = !$scope.formVisible
            };

    		$scope.partiesReceived = function(response){
				for (var i = 0; i < response.length ; i++) {
					var each_party = response[i].party

					var partyObject = {
						id: each_party.id,
						name: each_party.name,
						size: each_party.party_count,
						phone: each_party.phone
					}

					$scope.parties.push(partyObject)
				}    			
    		};

    		$scope.partiesFailed = function(response){
    			console.log("err");
    		};

        $scope.showAll = function(){
          $scope.search = {};
        };

    		$scope.addParty = function(isValid){
          if (isValid) {
      			PartyService.addAnotherParty($scope.formData)
  	        	.success($scope.partyAdded)
          }
          else {
            console.log("problem with your form mah nigga");
          }
    		};

    		$scope.partyAdded = function(response){
                console.log(response.party)

                var partyObject = {
                    id: response.party.id,
                    name: response.party.name,
                    size: response.party.party_count,
                    phone: response.party.phone
                }

    			$scope.parties.push(partyObject)
    			$scope.formData = {};
          $scope.formVisible = false;
          $scope.partyForm.$setPristine();

    		};

    		$scope.deleteAllParties = function(){
    			PartyService.deleteAllParties().success($scope.allPartiesDeleted)
    		};

    		$scope.allPartiesDeleted = function(response){
    			$scope.parties = [];
    		};

    		$scope.deleteParty = function(index){
    			console.log();
    			$scope.deleteIndex = index;
    			var partyId = $scope.parties[index].id
    			PartyService.deleteParty(partyId).success($scope.partyDeleted)
    		};

    		$scope.partyDeleted = function(response){
    			$scope.parties.splice($scope.deleteIndex, 1)
    		};

            $scope.sendText = function(index){
                $scope.smsIndex = index;
                var partyId = $scope.parties[index].id
                PartyService.sendText(partyId).success($scope.textSuccessful).error($scope.textFailed) 
                $scope.parties[index].disable = true;  
                $timeout(function(){
                  $scope.parties[index].disable = false;  
              }, 10000);             
            };

            $scope.textSuccessful = function(response){
              $scope.alerts.textSuccesful = true
              $timeout(function(){
                $scope.alerts = {};
              }, 4000);

            };

            $scope.textFailed = function(respn){
               $scope.alerts.textFailed = true
                console.log("IT FAILLLIED");
              $timeout(function(){
                $scope.alerts = {};
              }, 4000);
            };

            $scope.alertsExist = function(){
              var keys = Object.keys($scope.alerts).length
              if (keys == 0) {
                return false
              }
              else {
                return true
              }
            };


        $scope.init();
    }]);
&#13;
&#13;
&#13;

parties_controller.rb

&#13;
&#13;
class PartiesController < ApplicationController
  respond_to :html, :json, :xml

  def index
    @parties = current_business.parties
    respond_with(@parties)
  end

  def create
    @party = Party.create(name: params[:name], party_count: params[:size], phone: params[:phone], user_id: current_business.id)
    respond_with(@party)
  end

  def destroy
    @party = Party.find(params[:id])
    @party.destroy
    render :json => 'Success'
  end

  def destroy_all
    Party.destroy_all(:business_id => current_business.id)
    render :json => 'Success'
  end

end
&#13;
&#13;
&#13;

以下是我放入party / index.html.erb文件中的内容,以确定我是否可以使功能正常工作:

&#13;
&#13;
<div class="container" ng-app="Waiting">
	{{PartyService}}
	{{partiesReceived}}
	</div>
&#13;
&#13;
&#13;

&#13;
&#13;
   scope :api, defaults: {format: :json} do
    post '/send_text/:id' => 'send_text#send_text_message'
    resources :parties
    get '/parties/destroy/all'  => 'parties#destroy_all'
  end
&#13;
&#13;
&#13;

提前感谢您的帮助!

2 个答案:

答案 0 :(得分:1)

def User.find_by_profile_name(profile_name) self.find_by(username: profile_name) end

在app / models / user.rb

上添加此方法

答案 1 :(得分:0)

&#13;
&#13;
class User < ActiveRecord::Base
  mount_uploader :avatar, AvatarUploader 
  
  
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :authentication_keys => [:login]
  attr_accessor :login  
         validates :username, 
         :uniqueness => {
           :case_sensitive => false 
         }
          
          
          has_many :statuses
          has_many :reviews, dependent: :destroy 
          has_many :reservations, dependent: :destroy
          has_many :purchases, class_name: "Order", foreign_key: "buyer_id"
         
def self.find_first_by_auth_conditions(warden_conditions)
  conditions = warden_conditions.dup 
  if login = conditions.delete(:login)
    where(conditions).where(["username = :value OR lower(email) = lower(:value)", { :value => login }]).first
    else
        where(conditions).first
      end
end

def full_name
    if self.name.blank?
      self.email
    else
      self.name
    end
  end
end
&#13;
&#13;
&#13;