我有了的創建任務控制重定向後創建在某些情況下
一)有很多的選項
b)在正常工作新的屏幕快速任務創建屏幕,該屏幕具有多種方式與Rails應用程序最小動作並且只有最小字段才能快速創建。而操作的列表
的創建成功後我想
一)重定向到標準的節目形式
B)與空白快速創建框中回到快速編輯頁面重定向和列表中的新任務。
如果創建驗證失敗我想
一)重定向到與字段編輯屏幕高亮
B)重定向到快速創建屏幕領域突出和數據仍然存在。
我試過編輯創建respond_to if.save?但這似乎適用於這兩種情況下的一切。
有一點複雜的是,我創建任務一般(沒有客戶端選擇)或作爲客戶端自動選擇客戶端的嵌套路線,理想情況下,我想回到該嵌套的路線位置。
我想控制使用的,如果識別其中呼叫從
if from quick_create
if @task.save?
redirect
else
reload table and clear
if from new
if task.save?
任何想法來的參數,來應對呢?
增加電流控制器代碼和路線:
routes.rb
get 'tasks/quick_create' => 'tasks#quick_create'
-----
resources :clients do
match 'tasks/quick_create' => 'tasks#quick_create'
----
tasks_controller.rb
def create
@task = Task.new(params[:task])
@task.practice_id = current_user.practice_id
unless @task.recurring.present?
@task.build_recurring
end
@task.create_recurring_tasks
if params[:batch_task] == "Create Task"
@client = Client.find(params[:client_id])
@task.build_batch_task(@client)
end
respond_to do |format|
if @task.save
format.html { redirect_to @task, notice: 'Task was successfully created.' }
format.json { render json: @task, status: :created, location: @task }
else
format.html { render action: "new" }
format.json { render json: @task.errors, status: :unprocessable_entity }
end
end
end
def quick_create
if params[:client_id]
@client = Client.find(params[:client_id]).tasks
@tasks = @client.accessible_by(current_ability, :read).order(:due_date)
else
@tasks = Task.accessible_by(current_ability, :read).order(:due_date)
end
@task = Task.new
@task.status = "Not Complete"
#@task.task_files.build
@task.build_recurring
respond_to do |format|
format.html # index.html.erb
format.json { render json: @tasks }
end
end
Ibasically要控制的響應做到位的東西,如
if request.path.include? "quick_create"
並能夠在快速創建時標記錯誤。似乎有兩件事。 1. request.path if語句不起作用 2.嘗試反饋到quick_create頁面時,@task命中錯誤(因爲它認爲@task和@tasks都是我想的)。
反正....
創建兩個控制器或不同的動作來分割兩個不相關的方法。 – phoet
我在控制器中有快速創建單獨的動作方法,但是當它創建它仍然使用標準的創建方法(我認爲這可能是合理的,因爲那裏會有一些很好的底層軌道魔法)。我不介意,但我確實希望事後將它重定向到正確的位置。希望這是有道理的。 – Carpela