This is partially solved.

I have made a decorator

     order_decorator.rb

Spree::Order.class_eval do
    self.state_machine.after_transition :to => :payment,
                           :do => :instructions
    def instructions
      unless self.comments.exists?(:commentable_id => self.id)
       self.comments.create!
      end
    end
end


The problem:


+) FormBuilder is giving me an error on 'hidden-field-tag'
      Here is the portion of form_for with the hidden fields:


<%= form.fields_for :comments do |builder| %>
   <p>
     <%= builder.hidden_field_tag 'comment[commentable_id]', commentable.id%>
     <%= builder.hidden_field_tag 'comment[commentable_type]',
commentable.class %>
     <%= builder.hidden_field_tag 'comment[user_id]', current_user.id %>

This is the error message:


NoMethodError in Spree/checkout#edit

Showing *
/home/jet/RailsApps/spree/spree/core/app/views/spree/checkout/_payment.html.erb
* where line *#38* raised:

undefined method `hidden_field_tag' for #<ActionView::Helpers::FormBuilder:0x0000000af30598>

Removing hidden fields allows comment box to be displayed but with 4 copies of the comment box.


    Jet


On Sunday, February 17, 2013 4:24:59 PM UTC-8, Jet wrote:

I am attempting to use the spree_comments extension to have a comment box
in

Checkout/Payment

At this point I have installed the acts_as_commentable gem, spree_comments.
Both are working fine in Admin.

I have done the following to get a comment box in Checkout Payment:

+) In spree_comments:

app/models/spree/order_decorator.rb

Spree::Order.class_eval do
acts_as_commentable
# allow nested attributes, thus allowing comment field in an
order form
accepts_nested_attributes_for :comments
end

+) Above adds necessary :belongs_to and :has_many relationships


+) Create override, pass_commentable_from_edit.rb, on

spree/checkout/edit

Deface::Override.new(:virtual_path => "spree/checkout/edit",
:name => "pass_order_var",
:replace => "code[erb-loud]:contains('render @order.state')",
#pass @order as commentable
:text => "<%= render @order.state, :form => form, :commentable => @order %>")


+) Create override, checkout_payment_comment.rb, on

spree/checkout/_payment

Deface::Override.new(:virtual_path => "spree/checkout/_payment",
:name => "checkout_payment_comment",
:insert_before => "[data-hook = 'buttons']",
:partial => "spree/checkout/checkout_payment_comment" )


+) Create partial spree/checkout/_checkout_payment_comment.html.erb

<div id="payment_comment">
<fieldset id="comments">
<%= form.fields_for :comments do |builder| %>
<p>
<%= builder.hidden_field_tag 'comment[commentable_id]', commentable.id %>
<%= builder.hidden_field_tag 'comment[commentable_type]', commentable.class %>
<%= builder.hidden_field_tag 'comment[user_id]', current_user.id %>
<%= builder.label :comment, "Comment on Color Selection, Gift Status, Delivery" %><br />
<%= builder.text_area :comment, {:style => 'height:150px;', :class => 'fullwidth'} %> an
</p>
<% end %>
</fieldset>
</div>


At this point I am not getting any errors. However, the hidden fields and text area
are not rendering either.

I also tried changing the spree orders controller:

def edit
@order = current_order(true)
@order.comments.build #create comments
associate_user
end

...but I don't believe that was necessary.


Any suggestions are appreciated.

Thanks!

Jet



--
You received this message because you are subscribed to the Google Groups "Spree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Oskar de la Lumulumu at Nov 5, 2014 at 12:02 pm
    Hi Jet,

    this was very helpfull but still I wasn't able to get it working!

    Could you send me your order_decorator.rb

    Best Manuel

    Am Montag, 18. Februar 2013 22:24:42 UTC+1 schrieb Jet:
    Getting a

    can't mass-assign protected attributes nested error,

    which was corrected by adding:

    Spree::Order.class_eval do

    attr_accessible :comments_attributes
    accepts_nested_attributes_for :comments


    to the order_decorator.rb

    Jet

    On Monday, February 18, 2013 12:18:17 PM UTC-8, Jet wrote:

    Last error fixed by following changes:

    Original:

    <%= builder.hidden_field_tag 'comment[commentable_id]', commentable.id
    %>
    <%= builder.hidden_field_tag 'comment[commentable_type]',
    commentable.class %>
    <%= builder.hidden_field_tag 'comment[user_id]', current_user.id %>

    Changed to:

    <%= builder.hidden_field 'comment[commentable_id]', :value =>
    commentable.id %>
    <%= builder.hidden_field 'comment[commentable_type]', :value =>
    commentable.class %>
    <%= builder.hidden_field 'comment[user_id]', :value => current_user.id
    %>

    Cheers,

    Jet

    On Monday, February 18, 2013 11:45:50 AM UTC-8, Jet wrote:

    This is partially solved.

    I have made a decorator

    order_decorator.rb

    Spree::Order.class_eval do
    self.state_machine.after_transition :to => :payment,
    :do => :instructions
    def instructions
    unless self.comments.exists?(:commentable_id => self.id)
    self.comments.create!
    end
    end
    end


    The problem:


    +) FormBuilder is giving me an error on 'hidden-field-tag'
    Here is the portion of form_for with the hidden fields:


    <%= form.fields_for :comments do |builder| %>
    <p>
    <%= builder.hidden_field_tag 'comment[commentable_id]',
    commentable.id %>
    <%= builder.hidden_field_tag 'comment[commentable_type]',
    commentable.class %>
    <%= builder.hidden_field_tag 'comment[user_id]', current_user.id %>

    This is the error message:


    NoMethodError in Spree/checkout#edit

    Showing
    */home/jet/RailsApps/spree/spree/core/app/views/spree/checkout/_payment.html.erb*
    where line *#38* raised:

    undefined method `hidden_field_tag' for #<ActionView::Helpers::FormBuilder:0x0000000af30598>

    Removing hidden fields allows comment box to be displayed but with 4 copies of the comment box.


    Jet


    On Sunday, February 17, 2013 4:24:59 PM UTC-8, Jet wrote:

    I am attempting to use the spree_comments extension to have a comment
    box in

    Checkout/Payment

    At this point I have installed the acts_as_commentable gem,
    spree_comments.
    Both are working fine in Admin.

    I have done the following to get a comment box in Checkout Payment:

    +) In spree_comments:

    app/models/spree/order_decorator.rb

    Spree::Order.class_eval do
    acts_as_commentable
    # allow nested attributes, thus allowing comment field in
    an order form
    accepts_nested_attributes_for :comments
    end

    +) Above adds necessary :belongs_to and :has_many relationships


    +) Create override, pass_commentable_from_edit.rb, on

    spree/checkout/edit

    Deface::Override.new(:virtual_path => "spree/checkout/edit",
    :name => "pass_order_var",
    :replace => "code[erb-loud]:contains('render @order.state')",
    #pass @order as commentable
    :text => "<%= render @order.state, :form => form, :commentable => @order %>")


    +) Create override, checkout_payment_comment.rb, on

    spree/checkout/_payment

    Deface::Override.new(:virtual_path => "spree/checkout/_payment",
    :name => "checkout_payment_comment",
    :insert_before => "[data-hook = 'buttons']",
    :partial => "spree/checkout/checkout_payment_comment" )


    +) Create partial spree/checkout/_checkout_payment_comment.html.erb

    <div id="payment_comment">
    <fieldset id="comments">
    <%= form.fields_for :comments do |builder| %>
    <p>
    <%= builder.hidden_field_tag 'comment[commentable_id]', commentable.id %>
    <%= builder.hidden_field_tag 'comment[commentable_type]', commentable.class %>
    <%= builder.hidden_field_tag 'comment[user_id]', current_user.id %>
    <%= builder.label :comment, "Comment on Color Selection, Gift Status, Delivery" %><br />
    <%= builder.text_area :comment, {:style => 'height:150px;', :class => 'fullwidth'} %> an
    </p>
    <% end %>
    </fieldset>
    </div>


    At this point I am not getting any errors. However, the hidden fields and text area
    are not rendering either.

    I also tried changing the spree orders controller:

    def edit
    @order = current_order(true)
    @order.comments.build #create comments
    associate_user
    end

    ...but I don't believe that was necessary.


    Any suggestions are appreciated.

    Thanks!

    Jet



Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupspree-user @
categoriesrubyonrails
postedFeb 18, '13 at 7:45p
activeNov 5, '14 at 12:02p
posts2
users2
websitespreecommerce.com
irc#RubyOnRails

2 users in discussion

Jet: 1 post Oskar de la Lumulumu: 1 post

People

Translate

site design / logo © 2023 Grokbase