I'm attempting to use the flowplayer gem in my Rails 3 app. I've followed the installation instructions
Flowplayer Helper for Rails 3
applications
gem 'flowplayer' in your gem file
rails g flowplayer or rails g flowplayer commercial
add javascript_include_tag 'flowplayer.min.js' to your
application layout
read below
Usage
For JQuery
= flowplayer_for :video, '/flowplayer.swf', 'jquery' do
|player|
- player.playlist [{:url => "video_still.jpg" }, {:url =>
"video_512x288.flv", :autoPlay =>
false, :autoBuffering => true }]
- player.onLoad do
- 'this.unmute();'
For Prototype
= flowplayer_for :video, '/flowplayer.swf', 'prototype' do
|player|
- player.playlist [{:url => "video_still.jpg" }, {:url =>
"video_512x288.flv", :autoPlay =>
false, :autoBuffering => true }]
- player.onLoad do
- 'this.unmute();'
Configs are the same ones here
http://flowplayer.org/documentation/api/index.html
TODO
More documentation
After Step 1 I executed
bundle install
Which was successful.
For Step 2, I executed the first option
rails g flowplayer
Which was successful.
For Step 3, I added
= javascript_include_tag 'flowplayer.min.js'
to the head of my application.html.haml file; which was successful.
For Step 4, I added
%a#video{:style => "display:block;width:512px;height312px;"}
to my home.html.haml file; which was successful and the equivalent of
<a id='video' style='display:block;width:512px;height312px;'>
as per this HTML2HAML converter.
Now I've come to the last portion. I am using jQuery, but I have no idea where to put this last snippet of code.
Any help would be great thanks!
I know this is old but for anyone else - you can put the last bit of code right after the rest of your code. Caveat: There is a bug in the latest flowplayer gem. flowplayer_for only takes two parameters (causing it to always use jQuery) while the example shows three parameters. I've sent the author a pull request to change it.
So (in haml):
- content_for :head do
= javascript_include_tag "flowplayer.min.js"
%a#video{:style => "display:block;width:512px;height312px;"}
= flowplayer_for :video, '/flowplayer.swf'do |player|
- player.playlist [{:url => "video_still.jpg" }, {:url => "video_512x288.flv", :autoPlay => false, :autoBuffering => true }]
- player.onLoad do
- 'this.unmute();'
Related
How to replace this query in rails 5.0.6
with_scope(:create => {:article_id => article_id, :created_at =>
created_at}) do
yield
end
This article covers how to implement without the with_scope that was removed in Rails 4. Also there is a new syntax introduced in Rails 4, if I remember correctly, so your code would have looked like this if 'with_scope' was working.
with_scope(create: { article_id: article_id, created_at: created_at }) do
yield
end
I'm working on migrating a rather big project to Rails 3.
Here's my controller action:
def recent
#account = Account.find(session[:account_id])
render :layout => false
end
Here's my recent.json.erb file
formatted_account =
{
:code = 1,
:id = #account.id,
:prefix = 2
}
formatted_account.to_json()
I'm using jQuery.getJSON to get this data, when I get the response, this is what I get:
[{"code":1,"id":"1 "prefix":2}]
Instead of
[{code:1, id:1, prefix:2}]
I had to use safe_html in some other pieces of code to solve escaping issues like this but in this case I can't figure out how to solve without getting rid of the .json.rb file and rendering a json object in a proper way.
html_safe did the trick:
formatted_account =
{
:code = 1,
:id = #account.id,
:prefix = 2
}
formatted_account.to_json.html_safe
If you want to build up json from a template you'll need to use some kind of builder as ERB won't really cut it.
JBuilder comes commented out in a fresh Rails 3.2 Gemfile. Haven't used it myself but it seems well thought out with a clean DSL. There's also a list of links at the bottom of the README on the JBuilder github page.
RABL is another tool for building JSON, as well as supporting multiple other formats.
JBuilder
RABL
What sort of things OUTSIDE of the Rails codebase can affect asset precompilation?
My colleague is experiencing asset precompilation issues, while it works fine for me. We're running the same code. We have Gemfile and Gemfile.lock in version control, so those are identical, and application.rb is the same for both of us (so, for example, config.assets.enabled = true is set for both of us.)
Here are the two relevant files. The issue we're experiencing is below.
app/views/layouts/application.html.erb:
...
<%= stylesheet_link_tag "application", :media => "all" %>
...
app/assets/stylesheets/application.css:
/*
* This is a manifest file that'll automatically include all the stylesheets available in this directory
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*= require_self
*= require booking_availability_table
*= require bootstrap_and_overrides
*= require browse_coaches
*= require landing_pages
*= require layout
*= require lightbox
*/
note: Some of these files are .css, some are .css.less, and some are .css.scss.
The issue:
When loading the homepage, he gets the error
TypeError in Static_pages#home
can't convert nil into String
(in /path/to/app/assets/stylesheets/layout.css.scss)
Extracted source (around line #20)
20: <%= stylesheet_link_tag "application", :media => "all" %>
From experimental deleting, we see that it's only the .css.scss files that are causing the problem. Deleting the lines in application.css corresponding to SASS files stops the error from occurring and lets the page load. However, if we do so:
The home page then has tons of links to /stylesheets/___.css, which result in 404's, instead of the correct /assets/____.css as it does for me.
What we tried:
I tried stepping through loading the homepage on both our machines with debugger. Our code execution diverged here:
.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/sprockets/helpers/rails_helper.rb:
def stylesheet_link_tag(*sources)
...
sources.collect do |source|
if debug && asset = asset_paths.asset_for(source, 'css')
asset.to_a.map { |dep|
super(dep.pathname.to_s, { :href => path_to_asset(dep, :ext => 'css', :body => true, :protocol => :request, :digest => digest) }.merge!(options))
}
else
super(source.to_s, { :href => path_to_asset(source, :ext => 'css', :body => body, :protocol => :request, :digest => digest) }.merge!(options))
end
end.join("\n").html_safe
Specifically, the statement asset_paths.asset_for(source, 'css') raises an error for my colleague, but not for me.
We also tried uninstalling and reinstalling rails and rvm.
Oh, feels stupid... we fixed it. rm -rf'ing the entire directory and re-cloning it fixed it. I guess there was an extra file in there floating around or something.
So I have a simple ajax call to a page:
= link_to 'click me', my_path, :onclick => "if ($('#go').val() == "ok") { alert('going'); } else { return false; }", :remote => true do
This works just fine, I see the alert only when my field with id "go" has ok in there... but the issue is that the remote action triggers every time no matter what.
If this was not a remote link it would work just fine, not going through with the link, but it does not seem to behave the same way with a :remote => true ?
How can I achieve the expected result ?
Thanks,
ALex
The issue here is that the Rails UJS driver will see the data-remote and then perform the action because of a function like this in rails.js so perhaps try setting the property om your link inside the JS and remove the :remote => true. That might work however I dont know if rails.js would bind to that correctly or not.
Also, consider placing this JS in the application.js once you're done debugging just so you dont have inline JS all over your controllers.
- form_for(#post, :remote => true, :id => 'post_form') do |f|
Works as expected in FF and Chrome, but IE just processes the submit action normally, without any ajax request.
Not really seeing any info on this on the rest of the internet so I imagine I've done something wrong somehow. Ive used both the default rails.js, and the jquery version from the github page
Well, I don't know why the default rails version doesn't work for me here on IE, but I wrote this as a workaround:
if ($.browser.msie) {
var form = $('form#new_post');
form.find('input#post_submit').bind('click', function(){
var data = form.serializeArray();
$.ajax({url: '/posts', type: 'POST', data: data});
return false
});
}
And now it's working correctly. Shouldn't something like this be included in rails.js if this is in fact a problem with Rails, and not something that I've somehow done?
In our Rails 3 app the form tagged as data-remote wasn't turned into an AJAX form any longer after we had upgraded to jquery-rails 1.0.19. IE7 wasn't able to load the jquery.js - there seems to be a problem with version 1.7.1 of jQuery currently. After downgrading to jquery-rails 1.0.18 the problem disappeared again.