Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 获取控制器rails中的select标记值_Ruby On Rails_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 获取控制器rails中的select标记值

Ruby on rails 获取控制器rails中的select标记值,ruby-on-rails,ruby-on-rails-4,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.col

大家好,我不知道如何在视图中使用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%>

你的实际问题是什么?当我执行“渲染文本:@loc”时,我会看到一个空白屏幕。我正在等待所选的位置。
def index
  @city = Lawyerscitylist.select(:Location).uniq
  @service = Lawyersservicelist.select(:Service_Name).uniq
end

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