Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/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 不获取任何路由匹配[GET]”/显示“房屋搜索”38“;在轨_Ruby On Rails_Rails Routing - Fatal编程技术网

Ruby on rails 不获取任何路由匹配[GET]”/显示“房屋搜索”38“;在轨

Ruby on rails 不获取任何路由匹配[GET]”/显示“房屋搜索”38“;在轨,ruby-on-rails,rails-routing,Ruby On Rails,Rails Routing,我在我的控制器中定义了一个新方法,在点击搜索结果后显示我房子的定制展示页面 容纳控制器.rb def show_house_search @house = House.find(params[:id]) @photos = @house.photos end get '/show_house_search/:id', to: 'houses#show_house_search', as:'show_house_search' 然后我在routes.rb中声明了路由

我在我的控制器中定义了一个新方法,在点击搜索结果后显示我房子的定制展示页面

容纳控制器.rb

 def show_house_search
    @house = House.find(params[:id])
    @photos = @house.photos
  end
  get '/show_house_search/:id', to: 'houses#show_house_search', as:'show_house_search'
然后我在routes.rb中声明了路由

 def show_house_search
    @house = House.find(params[:id])
    @photos = @house.photos
  end
  get '/show_house_search/:id', to: 'houses#show_house_search', as:'show_house_search'
当我把它用作

<%= link_to show_house_search_path(house.id),id:'house_search' do %>
<li id="house-<%= house.id %>">
  <span class="user" style="font-size: 15px;font-weight: 200;text-decoration: dotted;"><%= house.title %></span>
  <span class="content"style="font-size: 15px;color: purple;font-weight: 600;">Price <i class="fa fa-inr"></i><%= house.price %></span>
  <span class="badge"><%= house.house_structure%></span>  </span>
  <span class="badge"><%= house.location%></span>  </span>
</li>
  <%end%>
同时,我还使用rails-routes

    show_house_search_path  GET     /show_house_search/:id(.:format) houses#show_house_search
请换一种方法

show_house_search_path(house.id) 

如routes.rb所示,路径是
/show\u house\u search/:id(:format)
,似乎
id
被视为
:format
,因此作为(.id)追加到路由中。

尝试以下代码:

<%= link_to show_house_search_path(id: house.id) ,id:'house_search' do %>


为什么不使用成员操作?有什么具体原因吗我已经在用了。。但是现在我需要额外的显示方法来显示我的搜索结果,这就是为什么我创建了自定义的显示方法。正如op评论的那样,这是不需要的,但出于某种原因被删除了。他忘了重新启动服务器。正如op评论的那样,这是不需要的,但出于某种原因被删除了。他忘了重新启动服务器。