title: How to invoke a method with in the controller and from a different controller
body: <p>I got stuck with this scenario. Let me explain as follows. I have a movies model, for a movie a user can give a rating and he can comment for a movie. So I have points table. Based up on the number of comments, rating and average rating e.t.c I wrote a method def points end in my movies controller. </p>
  
  <p>I have a comment controller and method in it separately for creating a comments, and for rating a movie I have written a a method in my movies controller for creating ratings. Hope Im clear till now. </p>
  
  <p>so my problem statement is. I want call this points method in movies controller at the time of creation of ratings and comments.</p>
  
  <p>for brief insight Im pasting my code here.</p>
  
  <p>In movies controller my two methods(ratings and points)</p>
  
  <pre><code> def rate
  
      @movie= Movie.find(params[:movie_id])
  
      @count=0
  
       @test= Rating.find(:last, :conditions=&gt;['movie_id=?', @movie.id])
  
       unless @test.nil? || @test.blank?
  
       @count= @test.count
  
  
       end
  
           if(params[:submitted])
  
              if @movie.ratings.create(:movie_id =&gt; params[:movie_id], :rate =&gt; params[:rating], :user_id=&gt; current_user.id, :count=&gt; @count+1) 
  
                points    
  
                flash[:success] = "Rating was successfully saved."  
  
              else
  
                flash[:error] = 'Error. Rating was not saved. Try again later.'
  
              end
  
              redirect_to @movie
  
            end
  
  
  end
  
   def points
  
    @user= current_user
  
    @movie= Movie.find(params[:movie_id])
  
    total_comments_by_user=Comment.find(:all, :conditions=&gt;['user_id=? AND movie_id=?',@user.id,@movie.id]).count
  
    user_who_rated= Rating.find(:all, :conditions=&gt;['user_id=? AND movie_id=?',@user.id,@movie.id])
  
      @user_who_rated.each do |ur|
  
        if @user=ur.user_id
  
          @ratings_of_each_user=ur.rate
  
       end 
  
         end
  
  
       @over_all_comments_of_movie=Comment.find(:all, :conditions=&gt; ['movie_id=?', @movie.id]).count
  
  
   @records=Rating.find(:all, :conditions =&gt; ['movie_id=?',@movie.id]).collect(&amp; :rate)
  
      unless @records.nil? || @records.blank?
  
        @average_rating = 0.0
  
          @records.each do |r|
  
            @average_rating += r
  
         end 
  
       @average_rating = @average_rating/@records.size
  
   end
  
  
     unless @ratings_of_each_user.nil? || @ratings_of_each_user.blank?
  
      if @total_comments_by_user.nil? || @total_comments_by_user.blank?
  
       else
  
     @div_one=@ratings_of_each_user*@total_comments_by_user
  
      @div_two=@over_all_comments_of_movie* @average_rating
  
        @total=0.0
  
        @total=@div_one.to_f/@div_two.to_f
  
  
   @find_user_in_points= Point.find(:all, :conditions=&gt; ['user_id=? AND movie_id=?',current_user.id,@movie.id])
  
    if @find_user_in_points.nil? || @find_user_in_points.blank?
  
     Point.create(:user_id=&gt; current_user.id, :movie_id=&gt;@movie.id, :points=&gt; @total)
  
       else
  
         @find_user_in_points.each do |f|
  
          if f.user_id= current_user.id
  
            f. update_attributes(:points=&gt; @total)
  
          end
  
       end
  
        end
  
        end
  
      end
  
    end
  </code></pre>
  
  <p>Now comments controller</p>
  
  <pre><code>def create
  
     @user=current_user
  
      @movie = Movie.find(params[:movie_id])
  
       @select_params= params[:choice_list] || []
  
       if @select_params.nil? || @select_params.blank?
  
         @comment = @movie.comments.create(params[:comment])        
  
  
        @comment.update_attributes(:user_id=&gt;@user.id, :commenter =&gt; @user.username)
  
       else
  
     @comment= @movie.comments.create( :commenter =&gt; "user", :body=&gt;params[:comment][:body] , :movie_id=&gt; @movie.id, :user_id=&gt;@user )
  
        end
  
      redirect_to movie_path(@movie)
    end
  
   def destroy
  
      @comment = Comment.find(:all, :conditions=&gt;['id=?',params[:id]])
      @comment.delete
      redirect_to movie_path(@movie)
    end
  </code></pre>
  
  <p>I have rate movie link on my view file and a form to add a comment to the movie. I just want to invoke that points method when ever a rating is created and comments are created so that i can perform my points caluculation internally and update my points table.</p>
  
  <p>Guide me please. Is it possible to call a method in one controller from the other controller if so how and tell me how to call a method in the same controller.</p>