2012-08-03 32 views
0

我希望设置来自标题的文本字段值。这里是代码在我的应用程序中设置文本字段的值

在android项目我设置在标题纬度ang经度,我想在轨道视图得到这个。

public static String getAddress(final String dir_atoken, final String data_atoken, final float lat, final float lng) throws Exception { 

     final HttpGet get = new HttpGet("http://192.168.1.4:3000/address/lookup"); 

     get.setHeader(LAT,String.valueOf(lat)); 
     get.setHeader(LNG,String.valueOf(lng)); 


     return getResponse(get, 200, true); 
    } 

这是我lookup_address控制器

def lookup_address 
    @lat = request.headers['Lat'] 
    @lng = request.headers['Lng'] 
    end 

这是我lookup_address.html.erb

<% form_for @location do |f| %> 
    <%= f.error_messages %> 

    <p> 
     <%= f.label :latitude %><br /> 
     <%= f.text_field :latitude, :value => request.headers['Lat'] %> 
    </p> 
    <p> 
     <%= f.label :longitude %><br /> 
     <%= f.text_field :longitude, :value => request.headers['Lng'] %> 
    </p> 
    <p> 
     <%= f.submit 'Create' %> 
    </p> 
<% end %> 

当我设置:value =>request.headers['Lat']它总是返回null。

我应该在这里做什么以获得空值?

+0

为什么你使用'lat'和'lng'作为标题;他们不应该成为参数吗? – 2012-08-03 07:44:32

+0

bcoz我将它存储在标题上。获得这个的唯一方法是request.headers – fish40 2012-08-03 07:47:06

+0

事实上,参数似乎是您要完成的最佳工具。您希望服务器为您的Android应用程序提供/执行什么操作? – 2012-08-03 07:52:50

回答

1

@location哪里建?猜测在控制器中设置@location.latitude@location.longitude会更正确。

def lookup_address 
    @location = Location.new #Not sure how you build the @location 
    @location.latitude = request.headers['Lat'] 
    @location.longitude = request.headers['Lng'] 
end 

lookup_address.html.erb

<% form_for @location do |f| %> 
    <%= f.error_messages %> 

    <p> 
     <%= f.label :latitude %><br /> 
     <%= f.text_field :latitude %> 
    </p> 
    <p> 
     <%= f.label :longitude %><br /> 
     <%= f.text_field :longitude %> 
    </p> 
    <p> 
     <%= f.submit 'Create' %> 
    </p> 
<% end %> 
相关问题