Skip to content

Instantly share code, notes, and snippets.

@bsylvain
Forked from anonymous/Form
Last active August 29, 2015 14:01
Show Gist options
  • Save bsylvain/96a0053d869dcd8a3694 to your computer and use it in GitHub Desktop.
Save bsylvain/96a0053d869dcd8a3694 to your computer and use it in GitHub Desktop.
undefined method `each' for "true":String
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"TTCSyAiy98vRZOKQDljKlkHYxRiLKBSnhL0iGUVMUq8=",
"shared_produit"=>{"shared"=>"true"},
"commit"=>"Autoriser partage",
"locale"=>"fr",
"produit_id"=>"37"}
= semantic_form_for @produit.shared_produit, :url => url_for(:controller =>"backend/shared_produits", :action =>"update",:produit_id=>@produit.id),:method=>:put do |f|
= f.input :shared, :input_html => { :value => true}, :as=>:hidden
= f.submit "Autoriser partage"
class SharedProduit < ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection
# attr_accessible :good_id, :owner, :shared, :sharing_start
belongs_to :good
validate
belongs_to :owner, :class_name =>'Shop',:foreign_key => "owner_id"
has_many :shared, :class_name =>'Produit',:foreign_key => "shared_from_id"
validates_presence_of :good
before_save :set_owner_id
private
def set_owner_id
self.owner=self.good.shop
end
end
def shared_produit_params
if current_admin_user.admin
params.require(:shared_produit).permit(:sharing_start,:free_price,:shared)
else
params.require(:shared_produit).permit(:sharing_start,:free_price,:shared)
end
end
def update
@produit=Produit.updatable_to(current_admin_user,current_shop).find(params[:produit_id])
@[email protected]_produit
if @shared_produit.update_attributes(shared_produit_params)
redirect_to :back, notice: "Partage modifié"
else
redirect_to :back, alert: "Erreur lors de l'édition"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment