具有多个值的单选按钮导轨

时间:2016-04-29 04:38:16

标签: ruby-on-rails ruby google-maps form-for

我希望在选择单选按钮时保存多个值。我尝试使用hidden_​​field执行此操作,但它不起作用。

<%= form_for @checkin do |f| %>
    <% @api["results"][0..9].each do |n| %>
      <%= f.label :name, n["name"] %>
      <%= f.radio_button(:name, n["name"]) %></br>
      <%= f.hidden_field :placeid, :value => n["place_id"] %>
    <%end%>
  <%= f.submit %>
<%end%>

我正在浏览Google maps api json响应,并希望在选择并提交单选按钮时保存名称和place_id。现在只有名称保存正确。

这是我使用checkin_params

创建新Checkin的控制器
class CheckinsController < ApplicationController

def index
    @checkins = Checkin.all
end

def create
    @checkin = Checkin.new(checkin_params)
    if @checkin.save
        redirect_to @checkin
    else
        render 'new'
    end
end

def show
    @checkin = Checkin.find(params[:id])
end

private

def checkin_params
    params.require(:checkin).permit(:name, :placeid)
end

以下是搜索控制器,我从

获取@api
class SearchesController < ApplicationController

def new 
    @search = Search.new 
end

def create
    @search = Search.new(search_params)
    @search.ip_address = "50.172.64.130"
    if @search.save
        redirect_to @search
    else
        render 'new'
    end
end

def show 
    @search = Search.find(params[:id])
    response = Search.get("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=#{@search.latitude},#{@search.longitude}&keyword=#{@search.keyword}&types=&rankby=distance&key=AIzaSyAny_eoq9b1UGL7Ow20vDTet9yIBb60BwA")
    @api = response.parsed_response
    @checkin = Checkin.new
end

private

def search_params
    params.require(:search).permit(:keyword)
end

对我现有想法的任何提示或对另一种方法的建议都将非常感谢!

0 个答案:

没有答案