Why ooyala's player.playMovie() method does'nt work? - ooyala

Why does ooyala's methods like play,pause, get current... wont work from console or from code.
i get:
TypeError: Object # has no method 'playMovie'

I'm guessing here, but it sounds like you are still using our V2 player (please try to upgrade) and haven't declared a callback in the url params for player.js. Without it, we will not initialize any JS apis.
See http://support.ooyala.com/developers/documentation/api/player_api_js.html for more details.

Related

Rails API and Strong PARAMS

I am trying to create an api to create record Foo using the rails-api gem.
I initially ran the generator command to tell rails to create a controller for me and it created this:
def create
#foo = Foo.new(foo_params)
#foo.save
respond_with(#foo)
end
And this (Strong params):
def foo_params
params.require(:foo).permit(:bar)
end
This is pretty standard stuff and will work when using form_for to submit data to the create method.
In my case, I'm creating a stand-alone API web service that will only interact via external API calls.
So the issue that I'm experiencing, is I don't know how to post the :bar param via API. I tried posting a :bar param, but this leads to a 'param is missing or the value is empty: foo' error. I understand why this is happening, but I have no idea how to get around this...
Is there a better way to do this or should I provide the api param in a different way?
PS. Currently my api POST call looks like this:
http://localhost:3000/api/v1/foo.json?bar=test#mail.com
you cannot use the ?+argument at the end of the url for a POST HTTP request, it's only for a GET request.
You must use the data component of the HTTP call, that is not embedded in the URL
therefore, you cannot just make this from your browser address bar and must use curl or a great tool as Postman (free on the chrome App Store)
and in this data field, you can include the object you want to post (postman gives you a neat key value interface to do so)
let me know if you need more details on the curl function for command line calls, but I recommend that you use a nice tool as Postman, so useful if you're not used to these calls
EDIT : this is the URL to get Postman : https://www.getpostman.com

How to use Monologue gem in native app (getting posts from Monologue into root app)

I'm using the Monologue gem (rails engine for blogging) and mounting it in my app at /blog, I want to get the posts with a certain tag and display those posts on the home page of my app ('/'). From rails c I can get a tag OR a post by doing Monologue::Tag or Monologue::Post but when I try to do Monologue::Tag.posts.published (like how he has the app getting the posts for a specific tag in source) I get "undefined method". I know it's because it's an engine, I'm just not familiar enough with engines to know what the proper syntax for this is?
Any help is much appreciated!
You are trying to get the posts for a specific tag right? Then, this is not what you want:
Monologue::Tag.posts.published
You are not specifying any tag here, you are calling the method posts on Monologue::Tag, but that is not a specific tag instance, it is the Monologue::Tag class.
Once you have a specific tag, you will be able to call posts.published on it, or as I see in the source, you can even call posts_with_tag
I guess that in order to try this, you could just get the first tag and then call the method:
Monologue::Tag.first.posts.published
Edit:
As I told you in the comment, your problem was that you were trying to call the method posts to an object that was not of the class Monologue::Tag (your model), but of the class ActiveRecord::Relation (a collection of Monologue::Tag objects).. Doing the first works, because is returning the first instance that was found by the where.
Another approach, if you know that you just want to fetch one instance, is to call find instead of where. Like this:
Monologue::Tag.find_by(name: "Goals")
This will return an instance of Monologue::Tag.

How is the `flash` in Rails made global to an application?

I'm curious as to how Rails achieves this. I notice that you can access the flash variable globally in an app, but it isn't prefixed with an # or a $.
I can also see that there's a method for accessing the flash and there's also an initializer as well that will set #flash, but how is it that I can call flash as a local variable?
Session
Further to apneadiving's answer, the flash is part of the middleware stack (ActionDispatch::Flash). It's actually a non-persistent session cookie:
--
From the docs:
The flash is a special part of the session which is cleared with each
request. This means that values stored there will only be available in
the next request, which is useful for passing error messages etc.
Much in the same way that params works (on a per request basis), the flash variable is only populated with data from the previous request.
--
Middleware
If you take apneadiving's comment, you'll see that the flash is created through the middleware stack - meaning the local nature of the variable is only set for that particular request (much the same as params). This is why you can access / set a flash message in any controller - because it's defined higher up the "middleware stack" - it provides a scope which appears global
I'm sure someone like apneadiving can explain it better than me, but that's how I see it

session[:key] = value doesn't work

I am trying to make use of session data in my application and for some reason I don't have something setup right.
The code:
session[:key] = some_value
Generates the following error:
The error occurred while evaluating nil.[]
Other controllers don't have an issue with the session, so I am guessing I missed some basic configuration thing somewhere.
Ok, I think I got it figured out now. I had a slightly more complex situation that my example. I actually had the following:
session[:chat_history][chat.from.id] ||= []
So I had an error with double array. I added the following:
session[:chat_history] ||= []
Problem was the first time I did this, I put it in a before_filter method. Apparently the session object is nil in the before_filter method, at least the way I have my application setup.
So I moved the initializer to the methods that actually access the session and life is good again.
It looks like the session variable is nil which makes me think the framework couldn't set it for one of these reasons:
Browser passed in no cookie for the session
Browser passed in a cookie but it didn't match anything the server expected
It was stated that some controllers work. Did something have the opportunity to create a session for the user before those controllers ran?

Can ActiveResource POST a create instead of PUTTing it when an id is specified?

I'm calling a rails app from another using ActiveResource. I need to supply the id of the new object to the first app (yes, controller create in this app knows how to handle receiving an id), so I do something like this:
a = ActiveResourceModel.new(:id => 1231231, :name => "test")
a.save
However, instead of doing POST to create a new resource it PUTs it, causing the receiving app to try to update the resource with id 1231231, which of course doesn't exist (I want to create it!), so I end up receiving a 404 error because of this.
Doing some testing the problem seems to be in ActiveResourceModel.new? which returns false, while ActiveResourceModel.exists? returns false too (Great, two methods which are supposed to be opposite return the same!).
Checking the AResource source and documentation, the new? method checks for the presence of the id and the exists? checks for the remote resource, making both returning the same.
Why exactly you need to pass the id to create a new object? Doesn't make sense.
Anyway, You can try to call create method instead of save.
I have the opposite problem. I EXPECT a PUT when calling AR.create with an id (since it implies the record already exists). However, with Rails 3.1 and up, it seems like the same code in Rails 3.0 that called PUT now in fact calls POST. Can anyone confirm this change? (Since I have control of the receiving server, I simply adjusted the POST code to have the same behavior as my old PUT code).

Resources