在我按下“创建任务管理员”按钮后,此表单 (views/workers/_form.html.erb) 将我重定向到任务管理员的索引。
我希望它将我重定向到“工人/索引”并将按钮更改为“更新任务”。
请问我该怎么做?
<%= form_for(@tasksadmin) do |f| %>
<% if @tasksadmin.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@tasksadmin.errors.count, "error") %> prohibited this tasksadmin from being saved:</h2>
<ul>
<% @tasksadmin.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.hidden_field :admin_mail, :value => @tasksadmin.admin_mail %>
<%= f.hidden_field :worker_mail, :value => @worker_mail %>
<%= f.hidden_field :task, :value => @tasksadmin.task %>
<div class="field">
<%= f.label :done %><br />
<%= f.check_box :done %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
这是我的workers_controller:
class WorkersController < ApplicationController
# GET /workers
# GET /workers.json
def index
@tasks_worker = Tasksadmin.where(:worker_mail => "alon.shmiel@gmail.com")
respond_to do |format|
format.html # index.html.erb
format.json { render json: @workers }
end
end
# GET /workers/1
# GET /workers/1.json
def show
@task_worker = Tasksadmin.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @worker }
end
end
# GET /workers/new
# GET /workers/new.json
def new
@worker = Worker.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @worker }
end
end
# GET /workers/1/edit
def edit
@tasksadmin = Tasksadmin.find(params[:id])
@worker_mail = "alon.shmiel@gmail.com"
end
# POST /workers
# POST /workers.json
def create
@worker = Worker.new(params[:worker])
respond_to do |format|
if @worker.save
format.html { redirect_to "@worker", notice: 'Worker was successfully created.' }
format.json { render json: @worker, status: :created, location: @worker }
else
format.html { render action: "new" }
format.json { render json: @worker.errors, status: :unprocessable_entity }
end
end
end
# PUT /workers/1
# PUT /workers/1.json
def update
@worker = Tasksadmin.find(params[:id])
respond_to do |format|
if @worker.update_attributes(params[:worker])
format.html { render action: "index", notice: 'Worker was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @worker.errors, status: :unprocessable_entity }
end
end
end
# DELETE /workers/1
# DELETE /workers/1.json
def destroy
@worker = Tasksadmin.find(params[:id])
@worker.destroy
respond_to do |format|
format.html { render action: "index" }
format.json { render json: @worker }
end
end
end