English 中文(简体)
铁路3阵列问题
原标题:Issue with Rails 3 array

在我的铁路3号座标中,每个用户的概况都有我想要补充的阵列。 这些项目是独一无二的,但在每个简介中增加两类。 然而,我感到不安的是,通过他们的身份证将项目简介与项目联系起来。

<>strongprofile>rb Model:

class Profile < ActiveRecord::Base
  belongs_to :user
  accepts_nested_attributes_for :user

  has_many :profile_todos
  has_many :todos, :through => :profile_todos

  def add_todo_inside_item(item)
    self.profile_todos.build :category =>  inside 
  end

  def add_todo_outside_item(item)
    self.profile_todos.build :category =>  outside 
  end
end

todo.rb 模式:

class Todo < ActiveRecord::Base
  belongs_to :profile
end

profile_todo.rb 模式:

class ProfileTodo < ActiveRecord::Base
  belongs_to :profile
  belongs_to :todo
end

<><><>Todo.new >提供以下信息:

>> Todo.new
=> #<Todo id: nil, name: nil, created_at: nil, updated_at: nil>

<><>Profile Todo.new 内容如下:。

>> ProfileTodo.new
=> #<ProfileTodo id: nil, category: nil, profile_id: nil, created_at: nil, updated_at: nil>

www.un.org/Depts/DGACM/index_spanish.htm I m 电话profile_todos in my profiles using:

<div id="todosheader">
  <p><%= @profile.first_name %>&nbsp;has&nbsp;<%= pluralize(@profile.profile_todos.count,  todo ) %>.</p>
</div>
<div id="todo-list">
  <div class="todos_inside">
    <h4>Inside&nbsp;(<%= @profile.profile_todos(:category => "inside").count %>)</h4>
    <p><%= @profile.profile_todos(:category => "outside") %></p>
  </div>
  <div class="todos_outside">
    <h4>Outside&nbsp;(<%= @profile.profile_todos(:category => "outside").count %>)</h4>
    <p><%= @profile.profile_todos(:category => "outside") %></p>
  </div>
</div>

如何在<代码>的简介中添加<代码>todo。 Todo: 姓名添加到: 类别/代码>上。 现在叫@profile.profile_todos的右边是空洞的。

请允许我说,我有“试验”一词,有“1”。 如果我试图在我的<编码>上添加<代码>Todo。 使用<条码>@profile.add_todo_inside_item(“试验”)的阵列,我看上去“试验”(<条码>,Todo到我的<条码>上> 插图_todos(类别=>“inside”)。

问题回答

我不敢肯定你们想要做些什么。

to应当是复数,你应当拯救父母。

class Profile < ActiveRecord::Base
    has_many :todos

    def new_inside_todo(params)  # takes a hash of all attributes, like new()
      params.merge!( {:category => "inside"} )
      self.todos.build( params )
      self.save(:validate => false)
    end

    def new_outside_todo(params)
      params.merge!( {:category => "outside"} )
      self.todos.build( params )
      self.save(:validate => false)
    end
end

class Todo < ActiveRecord::Base
   belongs_to :profile

   # has an attribute called category

   # if Todos belong to more than one class, make the relationship polymorphic
   #     belongs_to :parent , :polymorphic => true
end




相关问题
Remove ActiveRecord in Rails 3

Now that Rails 3 beta is out, I thought I d have a look at rewriting an app I have just started work on in Rails 3 beta, both to get a feel for it and get a bit of a head-start. The app uses MongoDB ...

When will you upgrade your app to Rails 3? [closed]

Now that the Rails 3 beta is here, let s take a little straw poll. Please tell us briefly what your application does and when you will upgrade it to Rails 3. Or, if you re not planning on upgrading ...

Bundler isn t loading gems

I have been having a problem with using Bundler and being able to access my gems without having to require them somewhere, as config.gem used to do that for me (as far as I know). In my Rails 3 app, I ...

bypass attr_accessible/protected in rails

I have a model that, when it instantiates an object, also creates another object with the same user id. class Foo > ActiveRecord::Base after_create: create_bar private def create_bar Bar....

concat two fields activerecord

I m so used to oracle where you can simply concat(field1, , field2) but if I m using activerecord to find the field1 and field2, and I need a space in between, how do I accomplish this? Cheers ...

热门标签