1

There are a lot of tutorials on the internet about how to create a rails app where a user can create, edit, delete a task.

I need to create an app where there is a pre filled list of tasks with checkboxes that the user can tick off.

Being a noob to rails, I can't really find any resources to point me in the right direction.

Any help will be appreciated.

Thanks

4

3 回答 3

2

您应该只添加一个名为prefill_todos!on的方法User,然后在创建时调用它。这是它的外观草图:

class User
  def prefill_todos!
    todos.create! name: "Buy Milk", deadline: (Date.today + 2.days)
    todos.create! name: "Use this app", complete: true
    todos.create! name: "Tell 3 others about this app", deadline: (Date.today + 1.week)
  end

  # Automatically add dummy todos after creating the object.
  # NOTE: Probably better to explicitly call user.prefill_todos! when you create user.
  after_create :prefill_todos!
end

注意:此答案仅涉及预填充 TODO 项目的问题。您需要遵循涵盖该内容的单独教程(或询问单独的堆栈溢出问题)。祝你好运!

于 2013-03-30T00:15:30.860 回答
0

为了创建一个默认为 true 的复选框,您可以在迁移中使用以下代码:

class AddTaskToUsers < ActiveRecord::Migration
  def up
    add_column :users, :task, :boolean, :default => 1
  end

  def down
    remove_column :users, :task
  end
end
于 2013-03-30T00:07:04.480 回答
0

好的,假设您所指的教程将创建的任务保存到数据库,那么您可以按照教程创建任务列表应用程序,然后使用 seed.rb 为数据库预先设置初始任务集。这里有一个关于在 railscasts上使用 seed.rb 的教程 。它有点过时了,但仍然与 rails 3.x 相关

于 2013-03-30T00:09:44.423 回答