原创作者: hideto
阅读:1356次
评论:0条
更新时间:2011-05-26
REST将我们的controller限制到7个actions(index/show/new/create/edit/update/desctroy)
这次我们就来看看怎样添加自定义的actions
我们创建了两个方法,我们需要修改routes.rb:
现在我们可以访问http://localhost:3000/tasks;completed了
我们来看看页面中怎样写该链接:
这次我们就来看看怎样添加自定义的actions
class TasksController < ApplicationController def idnex... def show... def new... def create... def edit... def update... def destroy... def complete @task = Task.find(params[:id]) @task.update_attribute :completed_at, Time.now flash[:notice] = "marked task as complete" redirect_to completed_tasks_path end def completed @tasks = Task.find(:all, :conditions => 'completed_at IS NOT NULL') end end
我们创建了两个方法,我们需要修改routes.rb:
map.resources :tasks, :collection => { :completed => :get }, :member => { :complete => :put}
现在我们可以访问http://localhost:3000/tasks;completed了
我们来看看页面中怎样写该链接:
<%= link_to "Mark as complete", complete_task_path(task), :method => :put %> <%= link_to "Completed Tasks", completed_tasks_path %>
评论 共 0 条 请登录后发表评论