section_controller:флажок не сохраняется в базе данных
def save
@section =Section.new(require_section)
@section.user_id = @level.id
if @section.save
flash[:notic]='post created'
redirect_to :action=>'index'
else
render :action=>'create'
end
end
def update
@section= Section.find(params[:id])
if @section.update_attributes(require_section)
flash[:notic]='post updated'
redirect_to :controller=>'admin',:action=>'index'
else
render 'edit'
end
private
def require_section
params.require(:section).permit(:title, :tag, :visible, :content,:short_content,:teaser,:category_ids)
end
create.html.erb:
<%= form_for :section,:url=>{:action=>'save'} do |f| %>
Title:<%= f.text_field :title ,:class=>'form-control'%>
.
.
.
<% Category.all.each do |cat| %>
<%= check_box_tag :category_ids,cat.id %>
<%= cat.name %>
<% end %>
<%= submit_tag 'submit',:class=>'btn btn-success'%>
<% end %>
</div>
модель:
class Categorization < ActiveRecord::Base
belongs_to :category
belongs_to :section
end
class Category < ActiveRecord::Base
has_many :categorizations
has_many :sections, :through => :categorizations
end
has_many :categorizations
has_many :categories,:through => :categorizations
после представить форму категории не хранится в базе данных, но после создана успешно
я проверил столбец базы данных и category_ids имеет пустую строку
также я следить за этим tutorial
Rails: 4 базы данных: postgresql
Вы очень хорошо показываете свой код, но вы можете объяснить немного более подробную информацию о том, какова ваша фактическая проблема. – planetmaker