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
--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.