# Problem getting handle to a model attribute

**URL:** <https://www.ruby-forum.com/t/problem-getting-handle-to-a-model-attribute/171086>\
**Category:** Rails\
**Created:** [June 26, 2009, 7:08am UTC](https://www.ruby-forum.com/t/problem-getting-handle-to-a-model-attribute/171086 "2009-06-26T07:08:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@vishy](https://www.ruby-forum.com/u/vishy)\
**Post date:** [June 26, 2009, 7:08am UTC](https://www.ruby-forum.com/t/problem-getting-handle-to-a-model-attribute/171086/1 "2009-06-26T07:08:10Z")

</div>

I am currently working on an app in which I a list of tasks displayed  
under a particular project. These tasks get displayed when the  
application first loads. I am setting this project as the current  
project. I have a method in my application controller which sets the  
last project created by the user as the current project.

//Code  
def current\_project  
@current\_project = Project.find(:last, :conditions =\> {:owner =\>  
current\_user.id})  
end

Now the user has other projects as well and he can open those projects  
as well. I can load those projects and get the tasks out of them using  
Project.find(params[:id]).tasks.  
But the problem is that I am trying to set this project to the  
@current\_project.

My tasks controller looks like this:

def index  
debugger  
@tasks = @current\_project.tasks  
@tasks = @tasks.sort\_by{|i| i[:position]}  
respond\_to do |format|  
format.html # index.html.erb  
format.xml { render :xml =\> @tasks }  
end

def load\_tasks  
debugger  
@current\_project = Project.find(params[:id])  
redirect\_to tasks\_url  
end

The load\_tasks action is being called on clicking of the project link  
so as to set the new value to @current\_project and then redirect to  
the index action. But this doesn’t seem to work and the value of the  
@current\_project stays the same in index action (which the value which  
was there when the application was loaded).

Is there a way that I can set the value to the @current\_project? I  
also tried to implement a getter and setter method but I don’t think I  
implemented it correctly or even if would help my cause here.

If someone can point me in the right direction that will be great.  
Also I am a newbie to rails, i would like to apologize in advance in  
case this is a real fundamental mistake.

Regards  
vishy
