-
-
Save bsylvain/96a0053d869dcd8a3694 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
undefined method `each' for "true":String | |
{"utf8"=>"✓", | |
"_method"=>"put", | |
"authenticity_token"=>"TTCSyAiy98vRZOKQDljKlkHYxRiLKBSnhL0iGUVMUq8=", | |
"shared_produit"=>{"shared"=>"true"}, | |
"commit"=>"Autoriser partage", | |
"locale"=>"fr", | |
"produit_id"=>"37"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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