0
메시지와 버튼이 연결된 일부 데이터를 저장하는 편지 양식이 있습니다. 나는 fields_for 메시지를 사용하고 fields_for 메시지 내에서 fields_for 버튼을 사용한다. 입력이 표시되지만 제출하면 버튼 데이터가 저장되지 않습니다.레일 : field_for fields_for 저장하지 않기
나는 레일 콘솔이 얻을 :
허가되지 않은 매개 변수 : 버튼
내 양식 :
def letter_params
params.require(:letter).permit(:campaign_name, :core_bot_id, :nb_recipients, :scheduled_at,
filters_attributes: [:id, :gender, :creation_date_start, :creation_date_finish, :first_name, :last_name, :segment => [], :timezone => [], :locale => []],
messages_attributes: [Message.attribute_names.map(&:to_sym).push(:_destroy), buttons_attributes: [Button.attribute_names.map(&:to_sym).push(:_destroy)]],
cards_attributes: Card.attribute_names.map(&:to_sym).push(:_destroy))
end
:
<%= f.fields_for :messages do |messages_fields| %>
<div id="text-messenger">
<div id="DIV_1">
<%= messages_fields.text_area :content, :required => 'required', class: "autoExpand", id: "intro-text-input", :maxlength => 640, placeholder: "Enter your text...", data: { 'rows' => '3', 'data-min-rows' => '3' } %>
</div>
<div id="add-message-button" class="add-button">+ Add Button</div>
<%= messages_fields.fields_for :buttons do |button_message_fields| %>
<div class="add-button-modal">
<h4>Enter the URL and the text to display on your button</h4>
<label>Button Text</label>
<%= button_message_fields.text_field :button_text, :maxlength => 20, placeholder: "Enter the text to display on the button..." %>
<br><br>
<label>Button URL</label>
<%= button_message_fields.text_field :button_url, placeholder: "Paste URL..." %>
<button type="button" id="validate_new_message_button">Add Button</button>
<p class="remove-link" id="delete_new_button">Remove Button</p>
</div>
<% end %>
</div>
<% end %>
문자 컨트롤러 내 허용 된 매개 변수
문자 모델 :
class Letter < ApplicationRecord
validates :campaign_name, :presence => true
belongs_to :core_bot
has_many :messages, dependent: :destroy
has_many :cards, dependent: :destroy
has_many :filters, dependent: :destroy
has_many :analytic_deliveries, dependent: :destroy
has_many :analytic_reads, dependent: :destroy
has_many :analytic_sends, dependent: :destroy
accepts_nested_attributes_for :filters
accepts_nested_attributes_for :messages
accepts_nested_attributes_for :cards
end
메시지 모델 :
class Message < ApplicationRecord
belongs_to :letter, optional: true
has_one :button, dependent: :destroy
accepts_nested_attributes_for :button
end
버튼 모델 :
메신저 모델에서class Button < ApplicationRecord
belongs_to :message, optional: true
belongs_to :card, optional: true
end
감사합니다. – AlphaNico