0

このメソッドのこのカスタムルートが例外をスローする理由を確認しようとしています:

tasks_controller.rb
    def run
        @task = Task.find(params[:id])
        @task.run_task
        flash[:notice] = "Running Task #{@task.task_name}in the background, please click     show to see results after a few seconds"
    redirect_to tasks_url
    end

タスクモデル task.rb

  def run_task
    if task.task_name == "game_state_count"
        task.description =  "Running task game_state_count"
    elsif task.task_name == "file_reader"
        task.description"Running task file_reader"
    elsif task.task_name == "copy_dupes_from_listings"
        task.description "Running task copy_dupes_from_listings"
    elsif task.task_name == "remove_dupes_from_listings"
        task.description "Running task remove_dupes_from_listings"
    end
  end

ルート.rb

     #For Admin Tasks run method
     match "tasks/run/(params[:id])" => "tasks#run", :as => :run_tasks_path

タスク/index.html.erb

<h1>Tasks</h1>

    <table>
      <tr>
       <th>Name</th>
       <th>Description</th>
       <th>Run</th>
        <th>Status</th>
        <th>Start Time</th>
      </tr>

    <% @tasks.each do |task| %>
      <tr>
       <td><%=task.name %></td>
       <td><%=task.description %></td>
       <td><%= link_to 'Run', run_tasks_path  %></td>
       <td><%=task.Status %></td>
       <td><%=task.start_time %></td>
       <td><%= link_to 'Show', task %></td>

     </tr>
    <% end %>
    </table>

    <br />

 <%= link_to 'New Task', new_task_path %>

例外

NameError in Tasks#index

Showing /Users/AM/Documents/RailsWS/appXXX/app/views/tasks/index.html.erb where line #16 raised:

undefined local variable or method `run_tasks_path' for #<# <Class:0x000001028b9ce8>:0x000001028b4450>

Extracted source (around line #16):

13:   <tr>
14:     <td><%=task.name %></td>
15:     <td><%=task.description %></td>
16:     <td><%= link_to 'Run', run_tasks_path  %></td>
17:     <td><%=task.Status %></td>
18:     <td><%=task.start_time %></td>
19:     <td><%= link_to 'Show', task %></td
4

1 に答える 1

1

ルートをこのように書き換えます

match "tasks/run/:id" => "tasks#run", :as => :run_tasks

更新:そして変更

<td><%= link_to 'Run', run_tasks_path  %></td>

<td><%= link_to 'Run', run_tasks_path(taks)  %></td>
于 2012-07-14T08:29:01.373 に答える