在我的应用程序中,我希望设置来自标题的动态文本字段值。以下是代码
在android项目中,我设置了标题纬度和经度,并尝试在rails视图上获取此设置。
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。
如果没有得到空值,我应该怎么做?
发布于 2012-08-03 15:55:11
@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']
endlookup_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 %>https://stackoverflow.com/questions/11791339
复制相似问题