Difficulty passing the title of the image to camera callback

My model has 2 attributes, image_uri and title. image_uri is defined as a blob attribute in image.rb. The intention is to allow the user to enter a title for the image and then to choose or take a picture and then store the same in the model.

Initially, there is no record, so on clicking "New" button on the index page, the user is taken to new.erb :

<div data-role="page">

  <div data-role="header" data-position="inline">

    <h1>New <%= @image.title %></h1>

    <a href="<%= url_for :action => :index %>" class="ui-btn-left" data-icon="back" data-direction="reverse">

      Cancel

    </a>

  </div>

  <div data-role="content">

    <form method="POST" action="<%= url_for :action => :create %>">

      <input type="hidden" name="id" value="<%= @image.object %>"/>

          <div data-role="fieldcontain">

            <label for="image[title]" class="fieldLabel">Title</label>

            <input type="text" id="image[title]" name="image[title]" <%= placeholder("Title") %> />

          </div>

         

          <div data-role="fieldcontain">

            <label for="image[image_uri]" class="fieldLabel">Image uri</label>

            <input type="text" id="image[image_uri]" name="image[image_uri]" <%= placeholder("Image URI") %> />

          </div>

     

      <input type="submit" value="Create"/>

    </form>

  </div>

</div>

Here's my create method in controller as well as the callback :

# POST /Image/create

  def create  

        Camera::choose_picture(url_for :action => :camera_callback)

        ""

  end

 

  def camera_callback

     if @params['status'] == 'ok'

       @image=Image.new({'image_uri' => @params['image_uri'],'title' => @params['title']})

       @image.save

     end

    

     WebView.navigate( url_for :action => :index )

     ""

   end

The problem is that the record is created, but only image_uri is saved, whereas title is not.

It looks like when camera_callback is called, @params['title'] is lost.

So, how do I pass in the value of title to the callback?

Or is there another/better way?

I'm sure this is a piece of cake to many of you folks!

TIA

Kutir Mobility
Hi Mark, Can you try the

Hi Mark,

Can you try the below snippet ?

  Camera::choose_picture(url_for :action => :camera_callback , :query => {:title => @params["image"]["title"]})

Check your params value on create method then pass that value to callback method using query

Visnupriya R

Kutir Mobility

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mark Nongkhlaw
Hi Visnupriya,Thanks for the

Hi Visnupriya,

Thanks for the response. I tried with your code and modified my callback thus :

       @image=Image.new({'image_uri' => @params['image_uri'],'title' => @image_params['title']})

       @image.save

But it didn't work. On clicking Create on the view, it allows selection of picture, picture selected, and then I'm shown an "Undefined" page. I read in the docs (http://docs.rhomobile.com/rhodesapi/camera-api) that the message in the camera callback is a POST message and contains only a few parameters, so maybe it cannot "carry along" the query as you suggested.

So, I did it this way (this is not the most elegant solution, but it works as long as user selects a pic from the dialog) :

I make image_uri as readonly field in all ERBs, except in show.erb, where I display the image using img tag.

This is my controller code :

  def create

    @image = Image.create(@params['image'])

        Camera::choose_picture(url_for :action => :camera_callback)

        ""

  end

  def camera_callback

     if @params['status'] == 'ok'

       @image = Image.find(:first, :conditions =>{'image_uri'=> ''})

       @image.update_attributes({'image_uri' => @params['image_uri']}) if @image

     end

     WebView.navigate( url_for :action => :index )

     ""

   end

But if you're from Spritle, I guess you already have an app (Change Bad to Good) where you allow the user to click a picture and enter the description for it. How did you do it there?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mark Nongkhlaw
I should add that it works,

I should add that it works, except that the image is not displayed

I used <img src="<%= @image.image_uri %>" /> in show.erb, and I found in the log, this line :

HttpServer| The file /app/Image/{143481959947002.03}/db/db-files/Image_06-19-2013_10.36.12__006.jpg was not found

On device, the image file is actually in appfolder/rho/db/db-files

I am attaching the log file to avoid clutter.

How should I proceed? Please advise.

Message was edited by: Mark Nongkhlaw

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Kutir Mobility
Use "Rho::RhoApplication.get

Use "Rho::RhoApplication.get_blob_path(relativeFilePath)" that will return the absolute path to a blob (such as a digital photo).

You can display it as

<img src="<%= Rho::RhoApplication.get_blob_path(@image.image_uri) %>" />

Thats the logic we used at Spritle app as well.

Visnupriya R

Kutir Mobility.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mark Nongkhlaw
Yes, I tried that,even this

Yes, I tried that,even this (2 colons before get_blob_path as per documentation) :

<img src="<%= Rho::RhoApplication::get_blob_path(@image.image_uri) %>" />

but its giving "Error Loading Page" in Rhosimulator, so I doubt if it will work in device.

What's more puzzling is that I have the sample app from an old webinar, where I don't have to use  Rho::RhoApplication::get_blob_path as simply doing src="<%=@image.image_uri%>" works even in device (tested in both WM & Android). Not sure if its because of layout.erb or not using jQM or what.

I can send that working webinar app if you are interested.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mark Nongkhlaw
OK, that webinar app is here

OK, that webinar app is here : https://github.com/rhomobile/webinar-samples/tree/master/imageupload

Take a look at webinar-samples / imageupload / app / Image / index.erb :

This snippet :

<% @images.each do |obj| %>

           

            <li>

                <img src="<%= obj.image_uri %>" width="300px"></img>

            </li>

works perfectly fine in this app, but not in mine. Wonder why.

Does layout.erb have anything to do with it?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Kutir Mobility
Does it have something to do

Does it have something to do with your old Rhodes version and latest Rhodes (3.5.1.13) ?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mark Nongkhlaw
No, I do not use Rhodes 3.5.1

No, I do not use Rhodes 3.5.1.13. My Rhodes version is 3.3.2 and I tested the webinar app and my app in the same version (3.3.2)

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Kutir Mobility
Can you send the zip file of

Can you send the zip file of your sample app ?

Visnupriya

Kutir Mobility

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mark Nongkhlaw
You want the one which does

You want the one which does NOT work?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Kutir Mobility
yes

yes

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mark Nongkhlaw
Attached. I used the webinar

Attached.

I used the webinar's app as a template, hoping that it will work. So it contains the old-style (jQTouch).

I identified the problem is in show.erb where log shows:

HttpServer| The file /app/Image/{143481959947002.03}/db/db-files/Image_06-19-2013_10.36.12__006.jpg was not found

That means my code is sending the above URL to the server instead of

/app/db/db-files/Image_06-19-2013_10.36.12__006.jpg

Hope you will be able to trubleshoot now

Thanks a lot!

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Kutir Mobility
I see nothing wrong in your

I see nothing wrong in your code.

Have you tried it on actual device ?

Visnupriya

Kutir Mobility

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mark Nongkhlaw
Its working now.I changed

Its working now.

I changed show.erb to display the image like this :

      <li>

        <img src="<%=Rho::RhoApplication::get_blob_path(@image.image_uri)%>" width='300px'></img>

      </li>

Not sure why it wasn't working earlier. Thanks anyway for your valuable time.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments