I am trying to insert a text after checkout email message. I'm found template in spree/order_mailer/confirm_email.text.erb
<%= Spree.t('order_mailer.confirm_email.dear_customer') %>
<%= Spree.t('order_mailer.confirm_email.instructions') %>
============================================================
<%= Spree.t('order_mailer.confirm_email.order_summary') %>
============================================================
<% #order.line_items.each do |item| %>
<%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) # <%= item.single_money %> = <%= item.display_amount %>
<% end %>
============================================================
<%= Spree.t('order_mailer.confirm_email.subtotal', :subtotal => #order.display_item_total) %>
<% #order.adjustments.eligible.each do |adjustment| %>
<%= raw(adjustment.label) %> <%= adjustment.display_amount %>
<% end %>
<%= Spree.t('order_mailer.confirm_email.total', :total => #order.display_total) %>
<%= Spree.t('order_mailer.confirm_email.thanks') %>
So I don't know how to add some text after this, there are no any selectors:
Deface::Override.new(
:virtual_path => "spree/order_mailer/confirm_email",
:insert_bottom => '*',
:partial => "spree/shared/confirm_email",
:name => "confirm_email",
:original => '3a8c298b4d9884a4d9f842b23fcb4fabf92ef0f3'
)
Could you advice me any ways to solve this?
Found solution here: How to add Spree email attachment (image) from products.images?. I'm created a new template /app/views/spree/order_mailer/confirm_email.text.erb and added my code here.
Short answer: You can't.
Long Answer: Unfortunately you cannot deface a text file as I tried recently. Reason is Deface needs structured data to parse the view, as detailed in the Spree Group discussion.
Only .deface, .html.erb.deface, .html.haml.deface or .html.slim.deface are the only override files allowed:
Deface::DSL does not know how to read '/spree/app/overrides/spree/order_mailer/confirm_email.text/append_text.text.erb.deface'.
Override files should end with just .deface, .html.erb.deface, .html.haml.deface or .html.slim.deface
Interestingly deface is actually able to test the selector on the file but still cannot override:
$ bundle exec rake deface:test_selector['spree/order_mailer/confirm_email.text',"erb:contains('order_mailer.confirm_email.thanks')"]
Querying 'spree/order_mailer/confirm_email.text' for 'erb:contains('order_mailer.confirm_email.thanks')'
---------------- Match 1 ----------------
<%= Spree.t('order_mailer.confirm_email.thanks') %>
The only thing you can do then is to override the file by creating app/views/spree/order_mailer/confirm_email.text.erb
Related
I am trying to generate dynamic CSS ids for javascript purposes, and the following code is giving me an error:
<%= form_for #item, html: { multipart: true } do |f| %>
<%= f.fields_for :item_images do |builder| %>
<%= image_tag builder.object.image.url(:large), :class => "cropbox", 'data-id' => builder.object.id %>
<% for attribute in [:crop_x, :crop_y, :crop_w, :crop_h] %>
<%= builder.text_field attribute, :id => attribute + builder.object.id %>
<% end %>
<% end %>
<% end %>
I know I'm not concatenating attribute and builder.object.id properly, but I've tried everything with no luck. I get this error message:
undefined method `+' for :crop_x:Symbol
Appreciate any help, thanks!
What is your expected result?
Can you p out what '''attribute''' is within your expression?
Also, have you tried .concat instead of '+'?
Away from my desk, but my suggestion is something like:
Example:
attribute.concat(builder.object.id)
Maybe need to convert attribute.to_i or .to_s into a responsive type or create a different dynamic CSS id solution
I have CarrierWave (0.6.1) and Nested Form gem installed. I have a Resource model with many Attachments which have a FileUploader.
I have a nested form where users can upload multiple files with one resource. I am following the section on github (https://github.com/jnicklas/carrierwave) that says how to make uploads work across redisplays unfortunately it's only for 1:1 ratio.
Here's the code that I have:
<%= nested_form_for #resource, :html=>{:multipart => true } do |f| %>
<p>
<%= f.label :title %>
<%= f.text_field :title %>
</p>
<%= f.fields_for :attachments, #attachment do |attachment_form| %>
<p>
<%= attachment_form.label :file %>
<%= attachment_form.file_field :file %>
<%= attachment_form.hidden_field :file_cache %>
<%= image_tag(attachment_form.file_url) if attachment_form.file? # DOESN'T WORK!!! %>
</p>
<%= attachment_form.link_to_remove "Remove this attachment" %>
<% end %>
<%= f.link_to_add "Add attachment", :attachments %>
<p><%= f.submit %></p>
<% end %>
Everything works and it populates the file_cache variable just fine for the attachment_form however I somehow need to add the following line in there to show the user the image of the document:
<%= image_tag(attachment_form.file_url) if attachment_form.file? %>
However there's a number of problems with this. First of all attachment_form is referencing the form_builder whereas I want the actual attachment. Second, attachment knows nothing about file.
Probably need to use another type of looping mechanism, but I'm new to Ruby so any help is appreciated.
Thanks all!
If you try this:
<%= image_tag(attachment_form.object.file_url) if attachment_form.object.file? %>
You will be able to show previous uploaded images. But if you want to display uploaded right now, you need to use something else. For example: https://github.com/blueimp/jQuery-File-Upload/wiki/jQuery-File-Upload-v4-for-Rails-3
Sorry, if I misunderstood your question.
I'm trying to add multiple product skus to an order at once.
Product has_many skus,
Order has_many order_lines
So in my order, I pull up a product and see all its skus (brown-small, brown-large) I then enter the qty of each I want to put on the order.
For some reason, it is only passing the :qty_sold params, and not the :sku_id - any reason why?
Routes:
post '/order_lines/create' => 'order_lines#create', :as => :create_order_lines
Form:
<%= form_tag create_order_lines_path do %>
<%= hidden_field_tag :order_id, #order.id %>
<% #product.first.skus.each_with_index do |sku, index| %>
<%= text_field_tag "order_lines[#{index}]", :sku_id, {:value => sku.id } %>
<%= sku.colour %>
<%= text_field_tag "order_lines[#{index}]", :qty_sold, {:value => ''} %>
<% end %>
<%= submit_tag "Add" %>
<% end %>
Output:
Started POST "/order_lines/create" for 127.0.0.1 at Fri Mar 16 23:13:27 -0400 2012
Processing by OrderLinesController#create as HTML
Parameters: {"commit"=>"Add", "order_id"=>"1", "authenticity_token"=>"JmImxbFUGLdM6Vt0rrS9RabSCUi1kV2QRTpWp34BBb4=", "utf8"=>"\342\234\223", "order_lines"=>{"0"=>"7", "1"=>"8", "2"=>"", "3"=>"9", "4"=>"", "5"=>""}}
This line is setting the key that you're having problems with
text_field_tag "order_lines[#{index}]"
So basically you're saying order_lines[X] = and since :qty_sold is the last option set to that key it's getting assigned that value.
To accomplish what you're trying to accomplish you would need to go a level deeper, like this
<%= text_field_tag "order_lines[#{index}][qty_sold]", :qty_sold, {:value => ''} %>
Honestly though, you should consider looking into the fields_for helper it does everything you want to accomplish and is more abstract.
This is untested but I think it should work
<% #product.skus.each do |sku| %>
<%= fields_for :order_lines do |order_line_fields| %>
<%= order_line_fields.text_field :sku_id, {:value => sku.id} %>
<%= sku.colour %>
<%= order_line_fields.text_field :qty_sold %>
<% end %>
<% end %>
I have a problem I can not resolve on a form
Here's my view:
<h1>create manager </h1>
<% form_tag :action => 'create_manager' do %>
<%= text_area :user, :nom %><br/>
<%= date_select :user, :date_embauche %>
<%= submit_tag "Submit" %>
<% end %>
and here is my controller:
def create_manager
tmp = params[:nom]
p(tmp)
render :partial => "adminpartial"
end
The problème is that params[:nom] return alltime nil.
I think i'm not using correctly the params variable.
Does anyone have an idea about this?
Did you look at the params passed in your logs?
I guess you might find something in params[:user][:nom]as explained here.
BTW, did you carefully read this?
i'm using ruby-1.8.7 and rails 2.3.5 in my rails app. i have a requirement to let the users upload their videos to youtube for which i'm using youtube_it gem. But i'm not sure if i'm following the documentation right.
here's my controller code:
class VideosController < ApplicationController
def upload
#upload_info = YouTubeIt::Client.new.upload_token(params, videos_url)
# params represent what values here, the doc says title, description but do i have to #build another form to get these values, i really need a working example.
end
and here's my form:
<% form_tag #upload_info[:url], :multipart => true do %>
<%= hidden_field_tag :token, #upload_info[:token] %>
<%= label_tag :file %>
<%= file_field_tag :file %>
<%= submit_tag "Upload video" %>
<% end %>
my other question is where am i supposed to specify the following statement which will initialize a new client for me:
client = YouTubeIt::Client.new(:dev_key => "developer_key")
i need some assistance here.
you are close just is missing a first step for give title and description to the video
for example
1 step) ask for title and description
send this to the controller and call to the method
#upload_info = YouTubeIt::Client.new.upload_token(params[:first_step], videos_url)
and this has to call to second step
2 step) the form that do you had
<% form_tag #upload_info[:url], :multipart => true do %>
<%= hidden_field_tag :token, #upload_info[:token] %>
<%= label_tag :file %>
<%= file_field_tag :file %>
<%= submit_tag "Upload video" %>
<% end %>
I going to give you a gist with real example
https://gist.github.com/1051122
for the last question you can initialize the client in your application_controller.rb, you can see it in the gist
I hope that it help you, good luck!
here you have a code example
http://www.chebyte.com/2011/09/15/youtube-it-demo-rails-app/