I am confused as to how to create a temporary User to retrieve / set
tasks to. I am fairly certain this is the direction I am supposed to
be moving in, but can’t figure out what I am doing wrong. Can anyone
point me in the right direction? I want to do this “the right
way”…rails 2.0, rest, etc.
Tasks controller
def index @user = find_user @tasks = Task.find(:all, :conditions => [“user_id = ?, completed
is null”, @user])
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @tasks }
end
end
…
def find_user
# if there isn’t a user return a new one with a fake name
unless session[:user]
session[:user] = User.new
end
session[:user]
logger.info “#{session[:user]}”
end
The advantage here is that you can choose to reorganize the
relationships between the user and tasks (e.g., assign one task to
multiple users through a join table when someone is sick or
unavailable) but your TasksController code does not have to change.
The current code is tightly coupled to the current object
relationship.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.