Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6149343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:26:13+00:00 2026-05-23T19:26:13+00:00

I got stuck with this scenario. Let me explain as follows. I have a

  • 0

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.

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.

so my problem statement is. I want call this points method in movies controller at the time of creation of ratings and comments.

for brief insight Im pasting my code here.

In movies controller my two methods(ratings and points)

 def rate

    @movie= Movie.find(params[:movie_id])

    @count=0

     @test= Rating.find(:last, :conditions=>['movie_id=?', @movie.id])

     unless @test.nil? || @test.blank?

     @count= @test.count


     end

         if(params[:submitted])

            if @movie.ratings.create(:movie_id => params[:movie_id], :rate => params[:rating], :user_id=> current_user.id, :count=> @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=>['user_id=? AND movie_id=?',@user.id,@movie.id]).count

  user_who_rated= Rating.find(:all, :conditions=>['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=> ['movie_id=?', @movie.id]).count


 @records=Rating.find(:all, :conditions => ['movie_id=?',@movie.id]).collect(& :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=> ['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=> current_user.id, :movie_id=>@movie.id, :points=> @total)

     else

       @find_user_in_points.each do |f|

        if f.user_id= current_user.id

          f. update_attributes(:points=> @total)

        end

     end

      end

      end

    end

  end

Now comments controller

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=>@user.id, :commenter => @user.username)

     else

   @comment= @movie.comments.create( :commenter => "user", :body=>params[:comment][:body] , :movie_id=> @movie.id, :user_id=>@user )

      end

    redirect_to movie_path(@movie)
  end

 def destroy

    @comment = Comment.find(:all, :conditions=>['id=?',params[:id]])
    @comment.delete
    redirect_to movie_path(@movie)
  end

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.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:26:14+00:00Added an answer on May 23, 2026 at 7:26 pm

    Don’t call another controller. If you need to share method, either make sure its in the model (if that’s the correct place for it) or in a shared controller like ApplicationController

    Also…
    unless @test.nil? || @test.blank? – String#blank? checks .nil? first. So the .nil? is not necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i got stuck with this problem, i can't find out how to get
I have been working on this for few hours and got stuck, so how
I have the follow problem. This is the situation i've got when user login
I'm learning Backbone.js and got stuck on this simple example. Could you explain what's
I'm trying to learn Lisp but I got stuck by this example (you can
In my way of learning drupal, I got stuck in this issue. I have
we have a (in our oppinion) very simple scenario here. But we got stuck
I got stuck in this problem for an hour. I am thinking this is
I got stuck with this problem. I wrap two tables inside of a h:form.
Since my AS3 and Php/Java knowledge is not good I got stuck on this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.