繁体   English   中英

从标题在文本字段上设置值

[英]set value on textfield from header

在我的应用程序中,我想动态设置来自标题的textfield值。 这是代码

在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。

我应该怎么做才能不获得空值?

@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 %>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM