我有一個小任務註冊表系統,用戶可以在其中創建,編輯和刪除他們的任務。我試圖創建一個「任務完成」按鈕,單擊時將給定的任務移動到另一個頁面。通過點擊按鈕將項目發送到另一頁
下面是我的控制器,視圖和路線:
class TarefasController < ApplicationController
before_filter :authenticate_user!
def index
@tarefa = current_user.tarefas.all
end
def show
@tarefa = Tarefa.find(params[:id])
end
def new
@tarefa = Tarefa.new
end
def edit
@tarefa = current_user.tarefas.find_by(id: params[:id])
end
def create
@tarefa = current_user.tarefas.new(tarefa_params)
if @tarefa.save
redirect_to @tarefa
else
render 'new'
end
end
def update
@tarefa = current_user.tarefas.find_by(id: params[:id])
if @tarefa.update(tarefa_params)
redirect_to @tarefa
else
render 'edit'
end
end
def destroy
@tarefa = current_user.tarefas.find_by(id: params[:id])
@tarefa.destroy
redirect_to tarefas_path
end
private
def tarefa_params
params.require(:tarefa).permit(:titulo, :descricao, :data, :time)
end
end
下面是我的看法:
<div class="row container-fluid">
<br><br><br><br>
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-info ">
<div class="panel-heading"><h3>Lista de tarefas</h3></div>
<div class="panel-body">
<button type="button" class="btn btn-default"><%= link_to 'Nova Tarefa', new_tarefa_path %></button>
<div class="table table-responsive">
<table class="table table-bordered">
<tr>
<th>Titulo</th>
<th>Descrição</th>
<th>Data e Hora</th>
<th>Cronometro</th>
<th>Estado da Tarefa</th>
<th colspan="3"></th>
</tr>
<% @tarefa.each do |tarefa| %>
<tr>
<td><%= tarefa.titulo %></td>
<td><%= tarefa.descricao %></td>
<td><%= tarefa.data %></td>
<td><%= timeago_tag tarefa.created_at, :nojs => true, :limit => 10.days.ago %></td>
<td><button type="button" class="btn btn-default"><%= link_to 'Mostrar', tarefa_path(tarefa) %></button></td>
<td><button type="button" class="btn btn-default"><%= link_to 'Editar', edit_tarefa_path(tarefa) %></button></td>
<td><button type="button" class="btn btn-default"><%= link_to 'Apagar', tarefa_path(tarefa), method: :delete, data: { confirm: 'Tem certeza?'} %></button></td>
</tr>
<% end %>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
我的路線:
Rails.application.routes.draw do
devise_for :users
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
resources :tarefas
match 'tarefas/tarefascompletas' => 'tarefas#completedtask', via: 'get'
root 'home#index'
end
有什麼問題嗎? – idej
我不知道如何創建這個點擊時發送的按鈕只發送完整的任務到另一個頁面。 –