Hi,
I'm really new to rails, so i programmed some stuff and today i read
some things about skinny Controllers, fat models.
My Controllers are really fat now. So i'm asking myself how can i
shrink my controllers and move the code to the models, especially in
fact of REST e.g. in focus on error codes?
code example:
# POST /tasks
# POST /tasks.xml
def create
@authorized = false
@addsubtask=false
@task = Task.new(params[:task])
if(@task.parent_id != nil ) #wenn parent id nicht leer ist
ueberpruefe ob Rechte fuer Uebertask da sind
#if ( current_user.is_owner_of? Task.find(@task.parent_id) ) ||
( current_user.is_moderator_of? Task.find(@task.parent_id) )
if ( current_user.has_rights_for_task? Task.find
(@task.parent_id) , ["Owner","Moderator"])
@authorized = true #Rechte da
@addsubtask = true
else
@authorized = false #Rechte da
@addsubtask = true
end
end
if ( ( (@authorized == false ) && (@addsubtask == false) ) ||
( (@authorized == true ) && (@addsubtask == true) ) )
respond_to do |format|
if(@task.priority == nil)
@task.priority = Priority.find(2)
end
@task.accepts_role 'Owner', current_user
if @task.save
#Task an
if @addsubtask
@task.move_to_child_of(@task.parent_id)
end
@task.recalculate_progress_recursive
flash[:notice] = 'Task was successfully created.'
format.html { redirect_to(@task) }
format.xml { render :xml => @task, :status
=> :created, :location => @task }
else
format.html { render :action => "new" }
format.xml { render :xml => @task.errors, :status
=> :unprocessable_entity }
end
end
else
respond_to do |format| #BENUTZER HAT KEINE RECHTE subtask
anzulegen
format.html { render :file => "#{Rails.public_path}/
401.html", :status => :unauthorized } #401 page laden
format.xml { render :xml => @task.errors, :status
=> :unauthorized } #statuscode bearbeiten
end
end
end
greetings
LeonS
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.