Я использую родословную gem в rails.When она установлена в модель, она получает атрибуты, такие как parent, parent_id, children и т. Д. Теперь у меня есть модельное сообщение, которое содержит два атрибута контента и content_title, и мы можем установить parent_id, но проблема в том, что я пытаюсь установить оба из них, только один обновляется. Вот мой код.Атрибуты обновления в рельсах с использованием «ancestry» gem
«parent_id» создается в «создании акции» и двумя другими атрибутами, как well.Now, когда я обновить его, как только этого «parent_id» обновляется, но когда я использую
#@page = Message.new(message_params)
В другие два атрибута content и content_title обновляются, а parent_id не обновляется.
class MessagesController < ApplicationController
layout false
def index
@messages = Message.all
end
def show
@message_id = Message.find(params[:id])
end
def new
@message = Message.new
end
def create
@page = Message.new(:parent_id => params[:parent_id],:content_title => params[:content_title],:content => params[:content])
#@page = Message.new(message_params)
if @page.save
flash[:notice] = "The Mesage was created succeffully"
redirect_to(:action => 'index')
else
render('new')
end
end
private
def message_params
params.require(:message).permit(:parent_id,:content_title,:content)
end
end
Это файл представления, который посылает данные
<div class="Pages new">
<h2> Create Pages</h2>
<%= form_for(:message, :url => {:action => 'create',:parent_id => @message_id}) do |f| %>
<table summary="Page form fields">
<tr>
<th>ParentID</th>
<td><%= f.text_field(:id) %></th>
</tr>
<tr>
<tr>
<th>Content Title</th>
<td><%= f.text_field(:content_title) %></th>
</tr>
<tr>
<th>Content</th>
<td><%= f.text_field(:content) %></th>
</tr>
</table>
<div class="form-buttons">
<%= submit_tag("Submit Form") %>
</div>
<% end %>
</div>
Есть ли способ, чтобы установить их как simultaneously.Am я делаю что-то не так?