0

I have a problem with calling methods. Here is the code from one of my Controllers:

class MethodsController < ApplicationController
  def details
    @title = "User Details"
    @fname = params[:first_name]
    @lname = params[:last_name]
    @exam_no = params[:exam_no]
    if @fname && @lname then
      @candidate = Candidate.create({:first_name => @fname, :last_name => @lname,:exam_number => @exam_no})         
      grades   #This method call doesn't work
    end

  end

  def grades
    @title = "Enter Grades"
    @candidate = Candidate.find(:last)
    @grades = params[:grades]
    @candidate.update_attributes({:grades => params[:grades]})
  end
end

The details method works fine, clicking the 'submit' button on the 'details' view creates the Candidate and I can 'link_to' the next page.

What I really want to do is: Click 'submit' and be automatically taken to the next view, 'grades' (which is also shown above). I thought a method call to 'grades' in 'details would work, but it doesn't. The 'grades' page title appears, but the view for 'details' still remains.

Is there some way to do this? Possibly call the 'grades' method from 'details' view? I know that's not best practice, but I'm stuck. (I tried @controller.grades but I get a NoMethodError - @controller is nil). I also tried render 'grades' but of course while it renders the view, it doesn't execute the code.

3
  • @AlokSwain You don't need to explicitly call render, as it will render a template with the same name as the action. Commented Nov 23, 2011 at 12:45
  • @Darth - oops. yea.. thanks for the correction goddamn these brain cramps. Commented Nov 23, 2011 at 13:00
  • Hi, thanks for the responses. Yeah, there's no call to render in the code now. I just stated that I tried it and while it rendered the view, it didn't execute any of the code in the corresponding method. Commented Nov 23, 2011 at 13:24

1 Answer 1

0

You might be looking for redirect_to instead of render

Redirect_to :action => 'grades'
Sign up to request clarification or add additional context in comments.

1 Comment

Hi. Thanks for the quick response. redirect_to works, in a way. It redirects to the specified page, but the check on whether the name fields are empty is not performed. So it lets a "blank" entry through.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.