14 Replies Latest reply on Jul 22, 2013 11:16 PM by Mark Nongkhlaw

    Difficulty passing the title of the image to camera callback

    Mark Nongkhlaw

      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">





        <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 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") %> />



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





      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)




        def camera_callback

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

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




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





      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!