views:

41

answers:

1

On a page in a model, I'm showing two links 'Choose Picture' and 'Take Picture'. I'm suceessfully successfully returning to that page after choosing picture and the chosen image is being shown correctly. However, when I click 'Take Picture', camera opens up, I take picture, the calling page loads with image shown and then immediately the index page in that model is shown.

Both the procedures are identical, with only change that one calls 'take_picture' and another calls 'choose_picture' can anybody tell me why in second case app redirects to index page in model?

abc_controller.rb:

def takepic
        $id = @params['id']
        Camera::take_picture(url_for :action => :camera_callback)
  end

  def choosepic
        $id = @params['id']
        Camera::choose_picture(url_for :action => :camera_callback)
  end

  def camera_callback
        if @params['status']='ok'
                @abc = Abc.find($id)
                new_attributes = {"q1img"=>@params['image_uri']}
                @abc.update_attributes(new_attributes ) if @abc
                @abc.save
                WebView.navigate( url_for :action => :mypage, :query => {:id =>
$id})

        end
  end

Calling page: mypage.bb.erb

<tr>
                           <td class="itemLabel">
                                        <%= link_to '[Choose Picture]',  :action => :choosepic , :query
=> { :id => @property.object }  %>
                                  </td>


                                  <td class="itemValue">
                                        <% if System::get_property('has_camera') %>
                                                <%= link_to '[Take Picture]',  :action => :takepic,  :query =>
{ :id => @property.object } %>
                                        <% end %>
                                  </td>
                   </tr>

===============

LOG:

I 09/09/2010 07:23:08:83 7a934000 RHO PropertyCon| Layout file: /apps/app/layout_erb.iseq. Content size: 2202

I 09/09/2010 07:23:08:83 7a934000 APP| RhoApplication: Using menu - {"Home"=>:home, Refresh"=>:refresh, "Sync"=>:sync,"Options"=>:options, "Log"=>:log, :separator=>nil, "Close"=>:close}

I 09/09/2010 07:23:08:83 7a934000 RhoConnection| dispatch end

I 09/09/2010 07:23:08:161 7a934000 RhoConnection| dispatch start

I 09/09/2010 07:23:08:223 7a934000 APP| RhoApplication: Using menu - {"Home"=>:home, "Refresh"=>:refresh, "Sync"=>:sync, "Options"=>:options, "Log"=>:log, :separator=>nil, "Close"=>:close}

I 09/09/2010 07:23:08:223 7a934000 APP| inside RHO.serve_index: /apps/app/index_erb.iseq

I 09/09/2010 07:23:08:223 7a934000 RHO Rho::RhoCon| inst_render_index

+1  A: 

At the end of your takepic and choosepic methods, you should use a redirect to where you want the app to be after the picture is taken. By not redirecting or rendering in takepic or choosepic you are using the default, which tries to render the view for 'takepic' or 'choosepic'.

You need this because in your camera_callback method you are only calling WebView.navigate if the result was 'ok'. If the user cancelled the picture, then it wouldn't change the navigation.

Brian