我的用戶模型中有一個has_many:active_posts表。我相當確信它設置正確。但是,當我嘗試將已經存在的對象添加到表中時,它似乎不起作用。任何幫助,將不勝感激!Ruby on rails table not save a additional object
模型user.rb
def addpost(other_post)
active_posts << other_post
end
認爲_feed.html.erb
<%= form_for @training_post, :html => {:class => "form-inline"}, url: confirm_training_post_path(post), method: :patch do |f| %>
<div class="form-group">
<%= f.submit "Confirm", class: "btn-primary btn-xs form-control" %>
</div>
<% end %>
控制器posts_controller.rb
def confirm
@post = Post.find_by(id: params[:id])
@user = User.find(params[:id])
@post.toggle!(:confirm)
@post.update_attribute(:propreceived, active_post_params[:propreceived])
current_user.addpost(@post)
current_user.deletepassivepost(@post)
redirect_to root_url
end
這是其他屬性? – Nithin