在轨道上的红宝石上的动作侦听器?

时间:2018-06-07 18:50:30

标签: ruby-on-rails database actionlistener

我有这个项目:https://todo-app-back-end-prospeed.c9users.io/ 它基本上是一个提醒Web应用程序。我尝试添加一个功能,用户点击复选框,值<Todo id: 24, description: "Publish project", pomodoro_estimate: 1, complete: nil 完成:nill 更改为完成:true或false `

<body>
  <div class="container2">
    <h1 id ="list">Workshop Todo List</h1>
    <ul>
      <% @todos.each do |todo| %>
        <li>
            <label class="container">
            <input type="checkbox"/ checked="checked">
            <a href = "/show/<%= todo.id %>"><%= todo.description %></a>
            <span class="pomodoro-estimate"><%= todo.pomodoro_estimate %> pomodoro</span>
            <span class="checkmark"></span>
            </label>
        </li>
      <% end %>
    </ul>
    <a class="noColor" href="/new/"><input class="add-new-todo-button" type="submit" value="Add todo"/></a>
    <h1 id="Pomodoro-technique">What is a pomodoro estimate?</h1>
    <p id="Pomodoro-technique-info">
      <strong>1 pomodoro = 25 minutes + 5 minutes break.</strong><br>
        For more info: <a href="https://www.focusboosterapp.com/the-pomodoro-technique">https://www.focusboosterapp.com/the-pomodoro-technique</a>
    </p>
  </div>
</body>

ToDoController:

class TodoController < ApplicationController
  def index
      @todos = Todo.all
  end
  def show
      # Gets number user typed in URL
      todo_id = params[:id]

      #Grab the todo with that id from the database
      @todo = Todo.find_by_id(todo_id)
  end
  def new
      #
  end
  def create
      t = Todo.new
      t.description = params['description']
      t.pomodoro_estimate = params['pomodoro_estimate']
      t.save
      redirect_to "/show/#{t.id}"
  end 
  def destroy
      t = Todo.find_by_id(params[:id])
      t.destroy
      redirect_to "/"
  end
  def edit
      @todo = Todo.find_by_id(params[:id])
  end
  def update
      t = Todo.find_by_id(params['id'])
      t.description = params['description']
      t.pomodoro_estimate = params['pomodoro-estimate']
      t.save
      redirect_to "/show/#{t.id}"
  end
end

我需要什么样的控制器?它是如何知道何时被点击的? 我只想指出正确的方向

1 个答案:

答案 0 :(得分:0)

我认为你的视图中的复选框不好。你需要这样的东西:

<%= f.check_box: field, {}, true %>