Created
March 20, 2012 15:07
-
-
Save anonymous/2136692 to your computer and use it in GitHub Desktop.
Controller file, I want to access the complete method Im getting the following error undefined local variable or method complete_tasks_path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <h1>Listing tasks</h1> | |
| <%= render 'newform' %> | |
| <table> | |
| <tr> | |
| <th></th> | |
| <th>Description</th> | |
| <th>Done</th> | |
| <th></th> | |
| <th></th> | |
| </tr> | |
| <% @tasks.each do |task| %> | |
| <%= form_for complete_tasks_path do %> | |
| <tr> | |
| <td><%= check_box_tag "task_ids[]",task.id %></td> | |
| <td><%= task.description %></td> | |
| <% if task.done %> | |
| <td> (Done) </td> | |
| <% else %> | |
| <td> </td> | |
| <% end %> | |
| <td><%= link_to 'Show', task %></td> | |
| <td><%= link_to 'Edit', edit_task_path(task) %></td> | |
| <td><%= link_to 'Destroy', task, :confirm => 'Are you sure?', :method => :delete %></td> | |
| </tr> | |
| <% end %> | |
| <%= submit_tag "Mark Selected as Done" %> | |
| <% end %> | |
| </table> | |
| <br /> | |
| <%= link_to 'New Task', tasks_path %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Mytasklistapp::Application.routes.draw do | |
| resources :tasks | |
| get 'task/:id/done', :controller => :tasks, :action => :done, :as => :done | |
| get 'tasks', :controller => :tasks, :action => :show, :as => :show | |
| get 'tasks/complete', :controller => :tasks, :action => :complete, :as => :complete | |
| # The priority is based upon order of creation: | |
| # first created -> highest priority. | |
| # Sample of regular route: | |
| # match 'products/:id' => 'catalog#view' | |
| # Keep in mind you can assign values other than :controller and :action | |
| # Sample of named route: | |
| # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase | |
| # This route can be invoked with purchase_url(:id => product.id) | |
| # Sample resource route (maps HTTP verbs to controller actions automatically): | |
| # resources :products | |
| # Sample resource route with options: | |
| # resources :products do | |
| # member do | |
| # get 'short' | |
| # post 'toggle' | |
| # end | |
| # | |
| # collection do | |
| # get 'sold' | |
| # end | |
| # end | |
| # Sample resource route with sub-resources: | |
| # resources :products do | |
| # resources :comments, :sales | |
| # resource :seller | |
| # end | |
| # Sample resource route with more complex sub-resources | |
| # resources :products do | |
| # resources :comments | |
| # resources :sales do | |
| # get 'recent', :on => :collection | |
| # end | |
| # end | |
| # Sample resource route within a namespace: | |
| # namespace :admin do | |
| # # Directs /admin/products/* to Admin::ProductsController | |
| # # (app/controllers/admin/products_controller.rb) | |
| # resources :products | |
| # end | |
| # You can have the root of your site routed with "root" | |
| # just remember to delete public/index.html. | |
| # root :to => 'welcome#index' | |
| # See how all your routes lay out with "rake routes" | |
| # This is a legacy wild controller route that's not recommended for RESTful applications. | |
| # Note: This route will make all actions in every controller accessible via GET requests. | |
| # match ':controller(/:action(/:id))(.:format)' | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TasksController < ApplicationController | |
| # GET /tasks | |
| # GET /tasks.json | |
| def index | |
| @task = Task.new | |
| case params[:done] | |
| when "1" | |
| @tasks=Task.find_all_by_done(true) | |
| when "0" | |
| @tasks=Task.find_all_by_done(false) | |
| else | |
| @tasks=Task.all | |
| end | |
| respond_to do |format| | |
| format.html # index.html.erb | |
| format.json { render :json => @tasks } | |
| end | |
| end | |
| def done | |
| @task = Task.find(params[:id]) | |
| @task.done = true | |
| 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 | |
| # GET /tasks/1 | |
| # GET /tasks/1.json | |
| def show | |
| @task = Task.find(params[:id]) | |
| respond_to do |format| | |
| format.html # show.html.erb | |
| format.json { render :json => @task } | |
| end | |
| end | |
| # GET /tasks/new | |
| # GET /tasks/new.json | |
| def new | |
| @task = Task.new | |
| @tasks = Task.all | |
| respond_to do |format| | |
| format.html # new.html.erb | |
| format.json { render :json => @task } | |
| end | |
| end | |
| # GET /tasks/1/edit | |
| def edit | |
| @task = Task.find(params[:id]) | |
| end | |
| # POST /tasks | |
| # POST /tasks.json | |
| def create | |
| @task = Task.new(params[:task]) | |
| @task.done = FALSE | |
| respond_to do |format| | |
| if @task.save | |
| format.html { redirect_to :action =>"index", :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 | |
| # PUT /tasks/1 | |
| # PUT /tasks/1.json | |
| def update | |
| @task = Task.find(params[:id]) | |
| respond_to do |format| | |
| if @task.update_attributes(params[:task]) | |
| format.html { redirect_to @task, :notice => 'Task was successfully updated.' } | |
| format.json { head :no_content } | |
| else | |
| format.html { render :action => "edit" } | |
| format.json { render :json => @task.errors, :status => :unprocessable_entity } | |
| end | |
| end | |
| end | |
| # DELETE /tasks/1 | |
| # DELETE /tasks/1.json | |
| def destroy | |
| @task = Task.find(params[:id]) | |
| @task.destroy | |
| respond_to do |format| | |
| format.html { redirect_to tasks_url } | |
| format.json { head :no_content } | |
| end | |
| end | |
| def complete | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment