Note that there are some explanatory texts on larger screens.

plurals
  1. POhow is this table updated if there is no model file?
    primarykey
    data
    text
    <p>I'm trying to manually update a db in Spree, but it has no model file. I want to know how to CRUD into the option_values_variants table.</p> <p>The code uses James Golick's Resource Controller, but I want to do it without.</p> <p><strong>models/option_value.rb</strong></p> <pre><code>class OptionValue &lt; ActiveRecord::Base belongs_to :option_type acts_as_list :scope =&gt; :option_type has_and_belongs_to_many :variants end </code></pre> <p><strong>controllers/admin/variants_controller.rb</strong></p> <pre><code>class Admin::VariantsController &lt; Admin::BaseController resource_controller belongs_to :product new_action.response do |wants| wants.html {render :action =&gt; :new, :layout =&gt; false} end create.before :create_before # redirect to index (instead of r_c default of show view) create.response do |wants| wants.html {redirect_to collection_url} end # redirect to index (instead of r_c default of show view) update.response do |wants| wants.html {redirect_to collection_url} end # override the destory method to set deleted_at value # instead of actually deleting the product. def destroy @variant = Variant.find(params[:id]) @variant.deleted_at = Time.now() if @variant.save self.notice = I18n.t("notice_messages.variant_deleted") else self.notice = I18n.t("notice_messages.variant_not_deleted") end respond_to do |format| format.html { redirect_to admin_product_variants_url(params[:product_id]) } format.js { render_js_for_destroy } end end private def create_before option_values = params[:new_variant] option_values.each_value {|id| @object.option_values &lt;&lt; OptionValue.find(id)} @object.save end def collection @deleted = (params.key?(:deleted) &amp;&amp; params[:deleted] == "on") ? "checked" : "" if @deleted.blank? @collection ||= end_of_association_chain.active.find(:all) else @collection ||= end_of_association_chain.deleted.find(:all) end end end </code></pre> <p>I believe this has to do with the models/option_value.rb:has_and_belongs_to_many :variants line. But how do I associate two items?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload