hy i'm trying to use this gem to generate a responsive nar_bar.
it work fine for me:
<%= nav_bar fixed: :top , brand: "Some_brand" , :responsive => true do %>
<%= menu_group pull: :right do %>
<%= drop_down "Services" do %>
<%= menu_item "a",a_path %>
<%= menu_item "b",b_path %>
<%= drop_down_divider %>
<%= menu_item "c",c_path %>
<% end %>
<%= menu_item "About",about_path %>
<%= menu_item "Portfolio",portfolio_path %>
<% end %>
now i want to use a logo.jpg image in brand instead "Some brand". Something like this:
<%= nav_bar fixed: :top , brand: :image_tag('logo.jpg') , :responsive => true do %>
i don't know if the helper method work whit image_tag. Can you help me?
I'm not entirely sure if this will work or not, but the code you showed definitely has an issue. Including the : before image_tag is telling Rails that image_tag is a symbol and not a method. You might try removing the extra colon.
<%= nav_bar fixed: :top , brand: image_tag('logo.jpg') , :responsive => true do %>
Related
I have a model Project and a model ProjectLine. Project has nested attributes for ProjectLine.
On my projects show view I'm listing project info with list of tasks.
<% #project.project_lines.each do |project_line| %>
<%= project_line.user.name %>
<%= project_line.description %>
<%= number_to_currency project_line.amount, precision: 0, unit: "USD ", separator: ",", delimiter: "," %>
<%= project_line.task_status_name %>
<% end %>
Tasks are created on project form using cocoon.
In the view above, after status name, I would like to have a button for each project line that changes the status.
The solution I found so far is to create a form.
<%= semantic_form_for #project_line do |f| %>
<%= f.hidden_field :status, :value=>2 %>
<%= f.submit 'ACCEPT', class: 'btn btn-primary btn-md' %>
<% end %>
I tried to place it on a partial on projects and call it on the loop <% #project.project_lines.each do |project_line| %>but i can't get it work.
How can I get a button for each project line to change project line status?
If i understand your request, somthing along the lines of
view
<% #project.project_lines.each do |project_line| %>
<%= project_line.user.name %>
<%= project_line.description %>
<%= number_to_currency project_line.amount, precision: 0, unit: "USD ", separator: ",", delimiter: "," %>
<%= project_line.task_status_name %>
<button class="accept_to_server">Accept</button>
<% end %>
javascript(jquery)
$.('.accept_to_server').on('click', function(){
$.ajax({
url: 'path/to/accept/route'
method: 'PUT' // or what method your route uses
data: {data:you, need:here}
}).done(function(data){
// update your view
}).fail(function(){
// something went wrong
});
};
Hope this helps out.
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
Is it possible to pass the value of checked check_box_tags within a form_for in Rails inside a hash?
Here is a very generic, basic version of the form:
<%= form_for(:object, :url => { :action => 'create', :id => params[:id]}) do |f| %>
<p>Field_a: <%= f.text_field(:field_a) %></p>
<p>Field_b: <%= f.text_field(:field_b) %></p>
<p>Field_c: <%= f.text_field(:field_c) %></p>
<p>Check boxes:</p>
<% check_box_choices_object_array.each do |s| %>
<%= check_box_tag(s.name, 1, false) %>
<%= .name %><br />
<% end %>
<%= submit_tag("Create") %>
<% end %>
Outputs roughly:
Field_a ___________________
Field_b ___________________
Field_c ___________________
Check boxes:
[] box_a
[] box_b
[] box_c
[] box_d
[] box_e
[] box_f
[] box_g
My problem is that since the available check boxes aren't actual fields in the object's table in the database (i.e. I'm not using check_box(:field) in the form), each checked check box gets passed as an individual parameter (i.e. "box_a" => "1", "box_b" => "1", "box_e" => "1"). I would like them to be passed as such:
:checked_boxes => {"box_a" => "1", "box_b" => "1", "box_e" => "1"}
This way, I can access them easily with params[:checked_boxes].
How do I do this, or, better yet, is there a better solution (I'm new to rails)?
I think you'd get the results you want if you wrap the checkboxes iterator in a fields_for :checked_boxes tag - or at least get you close to the results you want.
<%= form_for(:object, :url => { :action => 'create', :id => params[:id]}) do |f| %>
<p>Field_a: <%= f.text_field(:field_a) %></p>
<p>Field_b: <%= f.text_field(:field_b) %></p>
<p>Field_c: <%= f.text_field(:field_c) %></p>
<p>Check boxes:</p>
<%= f.fields_for :checked_boxes do |cb| %>
<% check_box_choices_object_array.each do |s| %>
<%= cb.check_box(s.name, 1, false) %>
<%= .name %><br />
<% end %>
<% end %>
<%= submit_tag("Create") %>
<% end %>
you can deal with no database attributes and models using attr_accessor
class Thing < ActiveRecord::Base
attr_accessible :name
attr_accessor :box_a, :box_b, :box_c
end
This way you can call these attributes in your form.
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
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 %>