chartkick how to pass hAxis.format to the underlying library - charts

I know you can use the :library=>{:pointSize=>0} syntax to pass options to the underlying charting library (Google charts in my case).
However, I can't figure out how to set the hAxis.format option. I've tried
<%= line_chart(#chart_data, :library=>{:pointSize => 0, :hAxis => "{format: 'yyyy-mm-dd'}"}, :min => #vmin, :max => #vmax) %>
and
<%= line_chart(#chart_data, :library=>{:pointSize => 0, :hAxis.format => "yyyy-mm-dd"}, :min => #vmin, :max => #vmax) %>
Both ways result in errors. What's the proper syntax for this?

So close.
<%= line_chart #chart_data, :library => {:pointSize => 0, :hAxis => {:format => "yyyy-mm-dd"}, :min => #min, :max => #max} %>

Related

Errors accessing hash in mojolicious

I am having issues accessing my hash in mojolicious.
my %managers = (
'IT' => {
'name' => 'Mike',
'id' => 1,
'num_of_employees' => 15,
},
'Sales' => {
'name' => 'John',
'id' => 33,
'num_of_employees'=> 50,
},
);
In perl I can access the data like $managers{'IT'}{'name'} would print out Mike. How would I do the same in mojolicious?
Being passed to my template
$g->stash(manage => \%managers);
<%== $manage{'IT'}{'name'} %>
The above throws an error. printing <%== $manage %> gives a HASH(0x1335430) location.
In your template $manage is a hash ref not a hash, so you need to dereference it by using the -> operator like this
<%== $manager->{'IT'}{'name'} %>

How to use PayPal for checkout in rails4

I am trying to add PayPal e-paiement to my RoR application. so I proceed as follow:
My panier.rb:
class Panier < ActiveRecord::Base
belongs_to :user
def paypal_url(return_path)
values = {
:business => 'r.karoui-buyer#loganddrive.com',
:cmd => '_cart',
:upload => 1,
:return => return_path,
:invoice => id
}
line_items.each_with_index do |item, index|
values.merge!({
"amount_#{index+1}" => item.price,
"item_name_#{index+1}" => item.book.title,
"item_number_#{index+1}" => item.id,
"quantity_#{index+1}" => 1
})
end
"#{Rails.application.secrets.paypal_host}/cgi-bin/webscr?" + values.to_query
end
end
my details.html.erb: where i call the PayPal service
<%= #panier.book_id %> | <%= #panier.price %> | <%= link_to 'acheter' , #panier.paypal_url(paniers_path) %>
but I got this error:
undefined local variable or method `line_items' for #
i just follow this railsCast tutorial :
http://railscasts.com/episodes/141-paypal-basics
what should I put in place of line_items.each_with_index do |item, index| if it is here the errors if not please help me to find out where is the problem
Try
def paypal_url(return_path)
values = {
:business => 'r.karoui-buyer#loganddrive.com',
:cmd => '_cart',
:upload => 1,
:return => return_path,
:invoice => id
}
values.merge!({
"amount_#{index+1}" => item.price,
"item_name_#{index+1}" => item.book.title,
"item_number_#{index+1}" => item.id,
"quantity_#{index+1}" => 1
})
"#{Rails.application.secrets.paypal_host}/cgi-bin/webscr?" + values.to_query
end

Form Element decorators Zend Framework

I'm using Zend Framework 1 and this library to integrate Twitter-bootstrap. It's great library, but I want to add new decorators for it (for Zend Form Element File), so that it looked like here
So instead of
<input id="image" type="file" name="image">
I want to render something like that (with all styles and javascript)
<span class="btn btn-success fileinput-button">
<i class="icon-plus icon-white"></i>
<span>Add files...</span>
<input type="file" multiple="" name="files[]">
</span>
I'm new to Zend Framework and do not know how to do that.
The question is, what have I put in library/Twitter/Form.php, in public/css and public/javascript to make it work?
Or maybe I have to do something else?
I tried to add decorators in Form.php, but no decorators applied (I do not remember what I did exactly)
So the main question is, how can I add this decorators for my Element in library/Twitter?
Edited:
I was working on the problem and managed to show a green button with a "plus" picture using jQuery-file-upload-ui.css (do not remember a name of the file) and changing $decorators in Form.php where code
if($element instanceof Zend_Form_Element_File)
is situated to
$decorators = array(
"ViewHelper",
array("Errors", array("placement" => "append")),
array("Description", array("tag" => "span", "class" => "help-block")),
array(array("ivanov2" => "HtmlTag"), array("tag" => "i", "class" => "icon-plus icon-white",'openOnly' => true,)),
array(array('close' => 'HtmlTag'), array('tag' => 'i', 'closeOnly' => true)),
array(array("ivanov" => "HtmlTag"), array("tag" => "span", "class" => "btn btn-success fileinput-button")),
array(array("innerwrapper" => "HtmlTag"), array("tag" => "div", "class" => "controls")),
array("Label", array("class" => "control-label")),
array(array("outerwrapper" => "HtmlTag"), array("tag" => "div", "class" => "control-group"))
);
But I still do not know how I can place an element with some content (for example with text):
<span>Add Files..</span>
And also I want to use drag and drop, but do not know how.

if else to render a different form in the view of a rails 2 app

I am trying to render one of two slightly different forms with an unless else:
unless many_items
form_tag purchases_url(:item1 => item1), :id => "id1_#{item1}", :method => "post", :class=> "order-form" do
else
form_tag purchases_url(:item1 => item1, :item2 => item2), :id => "upgrade_#{item2}", :class => "upgrade_form" do
end
rest of form
button
<%end%>
but I get an error, of course.
I don't really know haw to do this..
I used a nil to prevent from the second variable to exist
parent_order = item2.present? ? item2 : nil
form_id = gig.is_item? ? "1#{gig.id}" : "2#{gig.id}"
form_class = gig.is_item? ? "1" : "2"
form_tag purchases_url(:item1 => item1 ,:item2 => items), :id => form_id, :method => "post", :class=> form_class do
%>

Devise: Combine SignIn and ForgotPass forms into one

As shown in the attached image, I want to combine the Sign In form and the Forgot password form into one form. I am using DEVISE and RoR 3.2.5.
The Sign In form looks like:
= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => {:class => 'form-horizontal'}) do |f|
.inputs
= f.input :login, :required => false, :autofocus => true, :hint => "Enter either email ID or username"
= f.input :password, :required => false
= f.input :remember_me, :as => :boolean if devise_mapping.rememberable?
.form-actions{ :style => "padding-left: 160px;"}
= f.button :submit, "Sign in", :class => "btn btn-primary"
The Forgot password form looks like:
= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f|
= f.error_notification
.inputs
= f.input :login, :required => true, :hint => "Enter either email ID or username"
.form-actions{ :style => "padding-left: 160px;"}
= f.button :submit, "Send me reset password instructions", :class => "btn btn-primary"
One way is to create a new controller method that reads the value of the submit button.
Based on that value, you should be able to route between the 2 distinct actions.
Another -and probably more modern and clean- way would be to attach javascipt onclick events on one of the buttons that will ignore the form action and submit to a different route.
Rough example:
<script>
$('#forgot-submit-button').click(function(){
$('#my-form').attr('action','<%= forgot_password_path %>').submit()
});
</script>
Not enough time to test this, so please treat it as an example.