Rails:如何将params从friendly_id url传递给控制器​​?

时间:2015-07-24 09:29:48

标签: ruby-on-rails parameters controller friendly-id

我有一个网址:

Example.com/searchjobs/jobs/sales

所以,我只想通过'销售'我的控制器中@query变量的关键字,但它仍为零。

我尝试了几个教程,但他们只展示了如何在模型中使用friendly_id。

感谢您的帮助。

  

searchjobs_controller.rb



class SearchjobsController < ApplicationController

def jobs
    
    require 'nokogiri'
    require 'open-uri'
    @query = params[:qw]
 
  

   
    @xmls = Nokogiri::XML(open(URI.escape("http://api.indeed.com/ads/apisearch?publisher=apikey&q=#{@query}&l=&sort=date&radius=&st=&jt=&start=&limit=50&fromage=&filter=&co=uk&userip=#{@ip}&useragent=#{@useragent}&v=2")))
    
end
end
&#13;
&#13;
&#13;

  

模型searchjob.rb

&#13;
&#13;
class Searchjob < ActiveRecord::Base
  extend FriendlyId
  friendly_id :qw
 end
end
&#13;
&#13;
&#13;

  

的routes.rb

&#13;
&#13;
match '*qw',    to: 'searchjobs#jobs', via: :get
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

尝试更改您的路线:

match '/searchjobs/jobs/:qw', to: 'searchjobs#jobs', via: :get