获取控制器轨道中的选择标记值

时间:2014-04-11 18:42:37

标签: ruby-on-rails ruby-on-rails-4

大家好我不知道如何在视图中使用select标签并在rails中获取控制器中的选定值。我尝试了一些但没有得到结果。请有人帮助我。提前致谢。

index.html.erb

    <%=form_for :law, url: display_lawyers_path do |l|%>

      <h3>Enter the Location</h3>
      <%= l.select(:loc,  options_for_select(@city.collect {|c| [c.Location, c.id]}))%>

      <h3>Enter the Service</h3>
      <%= l.select(:ser, options_for_select(@service.collect{|s| [s.Service_Name, s.id]}))%>

      <div>
        <%= l.submit :submit %>
      </div>

  <%end%>

lawyers_controller

def index
  @city = Lawyerscitylist.select(:Location).uniq
  @service = Lawyersservicelist.select(:Service_Name).uniq
end

def display
  @loc =  params[:law][:loc]
  render text: @loc
end

0 个答案:

没有答案