1
我需要保存用戶的IP,但不知道如何做到這一點。如何使用rails獲取並保存到db用戶IP?
我的控制器看起來像這樣。
class CadastroController < ApplicationController
def create
valores = params.require(:cadastro).permit!
cad = Cadastro.create valores
end
end
我的形式看起來像這樣
<%= form_for Cadastro.new do |f| %>
<fieldset>
<input id="nome" name="cadastro[nome]" type="text" placeholder="Nome" class="form-control input-md" required="">
<input id="email" name="cadastro[email]" type="text" placeholder="E-mail" class="form-control input-md" required="">
<input id="telefone" name="cadastro[telefone]" type="text" placeholder="Telefone" class="form-control input-md">
<input id="cidade" name="cadastro[cidade]" type="text" placeholder="Cidade" class="form-control input-md">
<button id="download" name="download" class="btn btn-default" type="submit">Donwload</button>
</fieldset>
<% end %>
有人能舉個手?
我試圖將它保存爲一個字符串到數據庫,但它寫的唯一的事情就是「:: 1「,你有猜測嗎? –
這是一個IPv6環回地址(本地主機)。 – Mick
@AndréSasaki。我認爲你正在接到當地的請求。這就是爲什麼你得到一個ipv6格式,這是':: 1' – Panther