Rails 4, Carrierwave, jcrop, mobile to POST, not UPDATE - ruby-on-rails-4

Hoping someone can help me here - can't seem to figure this out.
I'm using Carrierwave to upload photos, and jcrop to crop. On my desktop, it works perfectly fine. I upload/create the photo, then the user crops/update the photo to the preferred size.
The WEIRD thing that happens is that when I'm on MOBILE (just mobile, not desktop/tablet), the update form_for will call POST, instead of UPDATE. But again, on desktop, everything works perfectly. Can anyone provide any help on why this behavior is happening on mobile only!?!
My code:
show.html.erb
<div class="container large-margin-left large-margin-right">
<div class="jcrop"><%= image_tag #photo.photo.large, :id=>'cropbox', :class=>'img-responsive' %></div>
<br>
<%= form_for [#user, #photo] do |f| %>
<% for attribute in [:crop_x, :crop_y, :crop_h, :crop_w] %>
<%= f.text_field attribute, :id=> attribute %>
<% end %>
<%= f.submit "Crop", :class=>'large-font pink-bg white caps sm-space', data: { disable_with: "Cropping..." } %>
<% end %>
</div>

wow - hopefully this helps someone else. But, it turns out Android doesn't play well with Model validations. (i had photo validations of size and image type), and this consequently threw off jcrop.

Related

autocomplete field is empty when editing form

I have a sample model in which belongs_to a patient model.Using rails-jquery-autocomplete I have managed to implement an autocomplete field where one can search patient's code and it works well. However when editing the form, the patient code is empty on the form.
How should I fix it?
App/views/sample/_form.html.erb
<div class="field">
<%= f.label :patient_code %><br>
<%= f.hidden_field :patient_id, id: 'patient_id' %>
<%= f.autocomplete_field :patient_code, autocomplete_patient_code_samples_path, id_element: '#patient_id' %>
</div>
I faced the same issue while editing the saved model, a quick workaround would be as follows:
...
<%= f.autocomplete_field :patient_code, autocomplete_patient_code_samples_path, id_element: '#patient_id', value: (!#sample.new_record?)? #sample.patient.code : '' %>
...
Assuming that the instance variable is #sample. Modify it according to your scenario. Cheers!

Rails 4 Index.html.erb loop

So I have the following index for my mailboxer conversations:
conversations/index.html.erb
<p><% #conversations.each do |conversation| %>
<% conversation.participants.each do |participant| %>
<% if participant != current_user %>
From: <%= participant.name %> <br />
<% end %>
<% end %>
Subject: <%= link_to conversation.subject %> <br />
Date: <%= conversation.updated_at.strftime("%a, %m/%e/%Y %I:%M %p") %> <br />
<%= link_to "Move to Trash", {:controller => "conversations", :action => "trash", :id => conversation.id}, :title=> "Move to Trash", :method=>'post' %> <br/> </p>
<% end %>
I came around to this because first it was saying there was no local method for "participant" and then it was saying there was no local method for "conversation." So I just made an each.do loop for both of them.
This works... It lists the sender and subject and the option to move each message to a trash folder... but it starts looping about 5 times per second to infinity. (I'm assuming this is hell on the server.)
THEN I noticed that this also happens for the users index.html and edit.html
Figured it out. I'll try to explain the problem and the solution as in-depth as possible.
Load the index.html.erb of a short page (user edit, index... whatever.)
tail the production or development.log file (or just look at the webrick screen
Notice that it's looping over and over and your cpu is heating up.
Turns out it was some crazy endless_scroll.js that never did anything for anyone... that all-of-a-sudden decided to activate and loop any page it deemed was too short.
Now the crazy thing (and mind you, I'm typing to myself at this point) is that, if you just threw in some random paragraphs... it would stop. Delete them? It would start looping again. (I guess according to the scroll limit.)
So I just deleted the endless_scroll.js and did a rake assets:clean and a rake assests:precompile.
Now everything is back to normal.

Showing Spree taxonomy tree on product page

I'm running Spree 2.2. I'm trying to get the standard taxonomy/filter list to appear on each individual product page in Spree, but I cannot find where it decides that there's sidebar content to be displayed. If anyone can shed any light on where/how that's decided I'd be most grateful.
On the front-end part of spree, more specific, on the index view of the products controller, route spree_frontend/app/views/spree/products/index.html.erb at the beginning of the file, it get's decided whether there will be displayed the taxons or not:
<% content_for :sidebar do %>
<div data-hook="homepage_sidebar_navigation">
<% if "spree/products" == params[:controller] && #taxon %>
<%= render :partial => 'spree/shared/filters' %>
<% else %>
<%= render :partial => 'spree/shared/taxonomies' %>
<% end %>
</div>
<% end %>
So what you can do is to write an override pointing at any part of the products/show view, in particular i suggest after the product_left_part_wrap" data-hook, wich is a wrapper for the sidebar on the products show view, so your deface could look something like this:
Deface::Override.new(
:virtual_path => 'spree/products/show',
:name => 'add_map_to_product_show',
:insert_after => '[data-hook="product_left_part_wrap"]',
:partial => "spree/products/the_taxons_and_filters"
)
And inside the file named _the_taxons_and_filters.html.erb located on app/views/spree/products/ you can add the code from above and include the taxons filters. Hope this was helpful.

rails chartkick google charts load times extremely long

I am trying to use chartkick to plot some charts with the google charts API. The problem is that the line to set everything up is taking 10-20 seconds to load. Here is the relevant line
<%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %>
Has anyone else had this problem? If so how do you fix it?
I don't know why this is, but I managed to get it to go fast by adding http: in the url
<%= javascript_include_tag "http://www.google.com/jsapi", "chartkick" %>
I generally get around this by grabbing a local copy of the file and only using it in development mode.
<% if Rails.env == "development" %>
<%= #include the local file here %>
<% else %>
<%= javascript_include_tag "http://www.google.com/jsapi", "chartkick" %>
<% end %>
Generally seems ok in production mode.

Adding a Class to a link_to Helper With Only 1 Parameter

I have the following:
<% #users.each do |user| %>
<% if user.profile %>
<%= link_to user do %>
<h2><%= user.profile.first_name %> <%= user.profile.last_name %></h2>
<% end %>
<% end %>
<% end %>
The above code works fine. What this code does is that it will output the first and last names of every user. These names are clickable and will take me to that user's page. My main issue is with the 3rd line. The issue I am having is that I am trying to get rid of the link underline, but I am unsure as to how to pass a class into it. Below is my attempt. My class "no-text-dec" is just one line of "text-decoration: none;"
<%= link_to (user, class: "no-text-dec") do %>
I'm new to Rails, but I understand that link_to has a body, url options, and then html options in that specific order, but how can I make it work in this case? The above line makes my application is crash, but it's the only thing I can think of that makes sense. I'm assuming it's because I am not giving it its body argument, but I'm not sure what that would be.
This should work fine if user contains url/path correct
<%= link_to(user, class: 'some_class') %> do
<span>Delete</span>
<% end %>
The space after method in sending argument in helper method link_to is crashing your application
you can give a try at irb
def test(a,b)
puts a; puts b;
end
test ("Ad","Cd")
It should throw an error