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.