Paperclip/MediaElement.js Player gem not working - ruby-on-rails-3

I'm trying to setup an app where I can upload .mp3 samples and play them back. Paul Irish recommends MediaElementPlayer, so I've started futzing around with it. I happily see that there is a gem available (Thank you Axel K.), but I just can't seem to get it working.
I've included the gem, and the asset pipeline seems to be loading everything, but when the page loads, there is a player for each song, but it shows 0:00 on each end and when I press play, nothing happens. The path to the songs are all correct as well.
Here is the code from my view:
<% #songs.each do |song| %>
<%= song.id %>: <%= song.title %><br/>
<audio id="player<%= song.id %>" src="<%= song.tune.path %>" type="<%= song.tune_content_type %>" controls="controls">
</audio>
<% end %>
<script>
$('audio').mediaelementplayer();
</script>
I copied the format and the audio tags directly from the MediaElementPlayer site example (which could be the problem, but I'm not seeing how...)
Also potentially of import, I'm using Paperclip to upload the .mp3s.
**UPDATE:
I just dropped a song into a public folder of my app and setup and audio tag for it, and it works. This makes me think there is something wrong with the way that songs are being uploaded. But all the info seems to be correct (path, content-type, etc...)...

So, I went through and just configured Amazon S3 (which is what I'll be using in production), and everything works without a hitch. There has to be something with where the file is stored locally, or how it's stored, or, heck, I don't know. But setting up S3 and storing the clips there works like a dream.

Related

Accessing attachment file for meta-information

A rails3 application with Carrierwave and MiniMagick is loading files. However in an attempt to get meta-information out it is hitting Errno::ENOENT
The helper method
def image
#document = Document.find(params[:id])
image = MiniMagick::Image.open(#document.production_file)
end
is called in the view
<%= image['width'] %>
but the error is specified as
No such file or directory - /uploads/document/production_file/1/leader_pg_600.jpg
Yet
localhost:3000/uploads/document/production_file/1/leader_pg_600.jpg
does show the file, and is identical to
<%= #document.production_file_url %>
why is this routing apparently not being seen?
ImageMagick is installed and the application is running a resizing manipulation.
Accessing the wrong form of information...
image = MiniMagick::Image.open(#document.production_file)
is only a string.
Should read
image = MiniMagick::Image.open(#document.production_file.path)

Images not showing in pdf

i have a problem i am deveoping a application using rails 2.3.8 . my problem is with the pdf. when a generated the pdf it shows all images in Linux.(ubuntu)
but the same code when i tried in windows7 the pdf is not showing the images in the body.the header and footer images are loading. the header and footer in the layout. i am using wickedpdf for pdf generation.
my code is
<%= wicked_pdf_image_tag "#{Rails.root}/public/images/master_student/profile/default_student.png" ,:width=>85,:height=>100 %>
the code working fine in the ubuntu but not working in the windows7..
please help
I just overcame a similar issue on Windows with images uploaded through Paperclip, because WickedPDF's wicked_pdf_image_tag helper requires the images to be in public/images.
I used the solution given here for that problem, but I still couldn't get the images to render in the PDF. Then I discovered that if I put the image into the public/images folder and referenced it that way, the wicked_pdf_image_tag helper rendered the image tag with forward slashes instead of backslashes after the 'file://'.
This is the helper method I ended up with, which replaces wicked_pdf_image_tag:
module ApplicationHelper
def wicked_pdf_image_tag_for_public(img, options={})
if img[0] == "/"
# Remove the leading slash
new_image = img.slice(1..-1)
image_tag "file:///#{Rails.root.join('public', new_image).to_s.gsub("/", "\\")}"
else
image_tag "file://#{Rails.root.join('public', 'images', img).to_s.gsub("/", "\\")}}", options
end
end
end

Document upload (doc, docx, odt, etc.) and display in Rails (as text)?

Does anybody know how to upload a document to later show in a Rails application (as text)? Is Paperclip the right gem to do this? If it is how? (I have uploaded images before with Paperclip).
I like Paperclip. It seems well documented, and has worked well for everything I have needed. (I don't personally know any of them, but the clever folks at Thoughbot have created some pretty useful stuff, for which I feel indebted to them).
Obviously, you need to add Paperclip to your Gemfile, and (if you are using bundler) do your bundle install
Add to your model
has_attached_file :aFile
Add to you controller something to catch whatever you name it in your view (probably in your create and update methods)
#profile.aFile = params[:profile][:aFile]
Probably should check for its existence, if it is a required param
if params[:profile][:aFile].blank?
redirect_to #profile
else
render :action => 'do_something_interesting_with_file'
end
And that's about it. Don't forget your config entries. For example, if you are using some kind of post-processing on the file
Paperclip.options[:command_path] = "/opt/local/bin/"
I found this to be extraordinarily helpful
RailsCast by Ryan Bates

gmaps4rails 1.4.8, infobox plugin 1.9, rails 3.2.2

I had the gmaps4rails gem version 1.4.5 working nicely on my Rails 3.2.2 app. I just grabbed the example infobox setup that was described in the 1.4.5 documentation at the time. Looked beautiful!
So I finally get around to checking it on IE8, and the infobox's background is absent, on Safari and Firefox I get a nice yellow with %75 opacity, on IE8 I get NO background at all.
After futzing around with the CSS, I gave up, and decided to grab the latest version of gmaps4rails 1.4.8. I notice it now supports the google infobox.js plugin. So I track it down, and find there are multiple versions, not knowing which version works with gmaps4rails 1.4.8, I choose infobox.js 1.9, the latest.
So I stick it in the app/assets/googlemaps.js manifest like so:
//= require infobox.js
//= require ./gmaps4rails.base.js.coffee
//= require ./gmaps4rails.googlemaps.js.coffee
I've tried several different permutations of when the infobox.js get's included.
I fire the whole thing off like so in usamap.html.erb:
<%= javascript_include_tag "lbrokers" %>
<%= gmaps("markers" => {"data" => #json, "options" => {"custom_infowindow_class" => "infobox", "auto_adjust"=>false}}) %>
With the lbrokers.js manifest looking like:
//= require gmaps4rails/googlemaps.js
When I hit that page, I get this:
google is not defined
http://localhost:3000/assets/infobox.js?body=1
Line 128
It was several months between the time I initially set up gmaps4rails, and now. Even though I installed the 1.4.8 Gem, what I REALLY did was just grab the gmaps4rails.base.js.coffee and gmaps4rails.googlemaps.js.coffee from gmaps4rails 1.4.8 on Github and pasted their contents into the previous files in app/assets/javascripst/gmaps4rails. This is the layout file rendered prior to calling usamap.html.erb:
<% content_for :html_foot do %>
<%= yield :scripts %>
<script type="text/javascript">
$(document).ready(function() {
var centerpoint = new google.maps.LatLng(38, -97);
gMap = new google.maps.Map(document.getElementById('map'));
gMap.setCenter(centerpoint);
});
Gmaps.map.infobox = function(boxText) {
return {
content: boxText
,disableAutoPan: false
,maxWidth: 0
,pixelOffset: new google.maps.Size(-140, 0)
,zIndex: null
,boxStyle: {
background: "url('http://google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.5/examples/tipbox.gif') no-repeat"
,opacity: 0.75
,width: "380px"
}
,closeBoxMargin: "10px 2px 2px 2px"
,closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
,infoBoxClearance: new google.maps.Size(1, 1)
,isHidden: false
,pane: "floatPane"
,enableEventPropagation: false
}};
</script>
<% end %>
That's the same infobox setup that worked fine on gmaps4rails 1.4.5. Now that I'm using the infobox.js plugin, noworky!
I have gone way wrong somewhere, either infobox.js 1.9 was the wrong choice.
Or I screwed up by just copying the two gmaps4rails coffee scripts and pasting them in app/assets/javascripts/gmaps4rails.
Or ?????
Anybody?
I have solved this for now by putting
<script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.9/src/infobox_packed.js"></script>
In the view's layout, and removing the
//= require infobox.js
From the manifest that was being used in the view where the map is shown. I was copying and pasting the various versions of infobox.js into my local copy and serving via the assets pipeline.
The background is still absent on IE8, but I'm using infobox 1.1.9, and there are later versions, hopefully they will fix the missing background.
I first noticed that the previously working gmaps4rails 1.4.5 setup stopped working when I upgraded from 1.4.5 to 1.4.6. So I put 1.4.5 back and carried on. When I noticed the IE8 missing infowindow background, gmaps4rails was by then at 1.4.8, and it acted the same as the attempted 1.4.6 upgrade. I can only assume that something changed between 1.4.5 and 1.4.6, requiring that you load the infobox.js plugin.
One other minor point, in 1.4.5 clustering was on by default, in 1.4.8 it's off by default, you have to turn it on by passing the option "do_clustering"=>true to the "markers" option hash.
Found the reason there was no background on IE8, I don't know when, probably years ago, I added this to my
<meta http-equiv="X-UA-Compatible" content="IE=7" />
Have no friggin idea when I did it, or why, but removing it fixed the missing background on IE8.

Rails3 UJS response not evaluated

It gives me the creeps,i'm done, i need some help here, i reverted multiple times back but i can't find the error.
Simple controller (customers),a simple form for adding a customer via :remote => true and the controller does respond_to do |format| { format.js } . Works fine, renders my create.js.rjs template.
I work for a few hours without making any javascript changes or changes to my controllers or authorization etc.. and when i try it again it's not working anymore.
What i mean with not working: Controller gets called, record saved, all partials rendered. But no javascript evaluated, not even a simple alert(1) at the beginning of the file.
I tried with different prototype.js versions and different rails.js versions, but nothing helped. I hope someone has a clue about this or already experienced this.
It's not that i don't want to post code. But it won't help. Its basic code that works and, after some changes where i don't know what i really changed (some locales here, some css there, html templates from a completely different controller a bit..)..
Currently developing with: ruby 1.9.2, rails 3.0.3, prototype 1.7 RC3, rails.js from github.
SOLVED
How stupid, I missed the part where the template naming changed. My application templace was named "application.rhtml". It worked until now. As it stopped to work, I changed it to "application.html.erb" and now it's working.