Video are not updaing on vzaar - ruby-on-rails

Hi I am using Rails, vzaar gem to upload the video.
title, description are updating but video file is not updating in vzaar. Any help would be appreciated.
video_controller:
def edit
#course = Course.find(params[:course_id])
#video = #course.videos.find(params[:id])
end
def update
#course = Course.find(params[:course_id])
#video = #course.videos.find(params[:id])
api = Vzaar::Api.new(:application_token => "my token", :login => "myloginname")
api.edit_video(#video.vzaar_id, :path => params[:video][:video].tempfile.path, :title => params[:video][:title])
if #video.update_attributes(:title => params[:video][:title])
redirect_to :back
end
end
title is updating but video with path is not updating. However with same technique i successfully created video in vzaar.
Thanks

It looks like you're trying to replace the actual video content here - is that correct?
If that's the case, it's not the edit_video method that you need to use in this case. As our documentation states, you can only change title, description, private and seo_url that way.
To replace a video, you'll need to use the upload_video method again, but supply a replace_id in the options that marks the video id you want to overwrite. In your case, it'll look something like this:
api.upload_video(path: params[:video][:video].tempfile.path, title: params[:video][:title], replace_id: #video.vzaar_id)
You'd also need to set the other options to match your previous uploads.
I hope this helps, and please let me know if you have any questions, or alternatively contact us on support#vzaar.com. And don't forget to check out the documentation, as that lists all the arguments available for each method.
All the best,
Dan

Related

how to copy a object with rails

I would like to use deep_dup to duplicate the parent and child objects and save as a new record using rails 5. I have been searching to see some example code to implement it on my project but so far i could not find anything.
so far i did this but it does not work.
def copy
#product = Product.find(params[:id])
#newproduct = #product.clone :include => :productlines
success = #newproduct.save
if success && #newproduct.errors.empty?
redirect_to (edit_product_path(#newproduct))
flash[:danger] = "Procut copied"
else
flash[:danger] = "Procut cannot be copied"
end
end
<%= link_to "Clone", copy_product_path(#product), :method => :put %>
the gem deep_cloneable is available but i could not understand the documantation, no idea how to use it.
Can anyone just show me a way to implement this on my project?
Would be really appreciated if someone can help.
It looks like you'll need to use the deep_clone method to include the productlines association (Also make sure it's not supposed to be product_lines).
#new_product = #product.deep_clone include: :productlines

Why are my API Pie parameters not showing up?

I created the documentation for my methods, and the top-level method description shows up along with its verb, but when I click on any of these links it tells me "Oops!! Method create.en not found for resource questions."
Here is an example of my code:
api :DELETE, '/questions/:id', 'Deletes question. Note that the delete cascades and also removes any child questions.'
param :id, :number
def destroy
#question = Question.find(params[:id])
#question.destroy_cascade
head :ok
end
And here's what the page looks like – all of these links take me to an error page
Weirdly, if I look at the json version it seems to be fine (i.e. it includes all the information).
I ended up needing to add these lines to the initializer:
config.default_locale = 'en'
config.languages = ['en']

Update not working with id attribute Rails 4

I've got below URL with get attributes sending request to the controller:
http://localhost:3000/videos/new/save_video?video_id=16&status=200&id=PhTHHldZJJQ
Constoller:
def save_video
#video = Video.find(params[:video_id])
if params[:status].to_i == 200
#video.update(:yt_youtube_id => params[:id].to_s, :is_complete => true)
Video.delete_incomplete_videos
else
Video.delete_video(#video)
end
redirect_to videos_path, :notice => "video successfully uploaded"
end
However I'm getting this error somehow:
ActiveRecord::RecordNotFound at /videos/new/save_video
Couldn't find Video with id=PhTHHldZJJQ
Is there a reason why it's not finding from :video_id?
I cannot figure this out...
ActiveRecord ids are integers. You've passed in a string to find which won't convert to an integer, so it will always fail.
It seems that it is trying to search the video using :id and not :video_id. It is possibly another gem (like CanCan), which might be trying to load the video before the action starts, in a filter. Or it might be something else in the controller, can you post the full code of the controller?
If you just want this to work, use :id as the variable to send the video id, instead of :video_id.

Rails Rendering Action in Different Controller

So I have a controller called Music with one action which is index. On the music/index.html page I list out a bunch of Songs (via a Song model) and at the bottom I have a for to create a new Song.
Song has validations which I have tested and work just fine. When the new Song saves in controller Songs action create I redirect_to => 'music_index_path' so the person can see the new song in the list. However when the Song does not save (does not pass validations) then I cannot use redirect_to since the form error_messages do not carry over. I need to use render but cannot say render :controller => 'music', :action => 'index.
My goal is to be able to show the error messages for the Song form ON the music/index.html page.
How should I go about this. I am open to other ideas (like changing up controllers) as well.
Thanks!
It sounds to me like Music should be a part of Song, or the other way around. You can always use routes to disguise it as one or the other to the user.
song/index sounds to me like it should display all songs, which is all music does anyway.
My first thought is that we need to rethink this process. Assuming you're using RESTful controllers, it's unclear to me why you would need a Music controller and a Song controller... how are those resources different? The next relevant question would be, why is it not sufficient to show errors via Song#create ? I mean, they couldn't get it right when it was just a form, is the distraction of additional content likely to help? :)
With that said, here is a possible solution. (Given that you didn't paste your code, I'm making a lot of assumptions here.)
<hack>
first, extract the form parts from songs/new to songs/_form, then from the music/index view, render :partial => songs/_form, and in the songs controller, render :action => '../music/index' (this is called a hackity-hack.) Because it's a hack, you will almost certainly need to go into music#index and add #song = Song.new
</hack>
If you start running on edge, the ability to pass a flash through a redirect was just added...but that doesn't really get you there.
The simplest solution though, is that you need to render index, but set up all of the variables that are needed for that page. If you factor that out into a separate module or method, you can call it from both the index action and the save failure.
def index
setup_for_index
end
def create
#song = Song.new(params[:song])
#song.save
#...
#on failure
setup_for_index
render :controller => "music", :action => "index"
end
def setup_for_index
#songs = Song.all
#etc
end
The other thing you could do is use form_remote_for and have the song form just update the div on failure. Then use an RJS template return type reload the whole song list on success.
While I want to reiterate what others have stated about your resource architecture deserving a second look, you can certainly render views for other resources using the :template option:
render template: 'music/index'
Why not a simple if request.post? conditional in the index action's view rather than redirecting to another page?
You can also try using flash[:song_save_error] to pass the error conditions back to your Music controller.
http://api.rubyonrails.org/classes/ActionController/Flash.html
You could try render :file => ...

accessing POST parameters

When I add a new "product" using my scaffold create rails app, the following line properly adds a new product
#product = Product.new(params[:product])
When I try to add a new product using the following URL (trying to POST data up from a java program).
http://localhost:3000/products?serial=555&value=111
The product is not created, however I can access the "serial" and "value" values like this:
#product = Product.new
#product.serial=params[:serial]
#product.value=params[:value]
#product.save
To further confuse me, if I use the rails app to add a new product, the params[:serial] and params[:value] variables are empty.
Can someone please point me in the right direction.
Thanks
The Model.new method takes a hash.
params[:product] actually contains something like {:serial => 555, :value => 111}
The url you would want to use is:
http://localhost:3000/products?product[serial]=555&product[value]=111
(Make sure that you are indeed using POST)
If you want to keep your current url scheme you would have to use:
#product = Product.new({:serial => params[:serial], :value => params[:value]})
You can also determine exactly what is available inside of params by printing it out to console using:
p params
Good luck!

Resources