开发者

Ruby on Rails Problems with Views (rhml / html.erb)

I'm having a problem with regards to views in ruby on rails.

Basically I have a regular project which lists the details just fine on

http://localhost:3000/stores/ which loads the code found within index.html.erb

Now, i have scaffolding etc all in place, however when i try to load

http://localhost:3000/stores/search which SHOULD load code from search.rhtml (should this be changed to .html.erb or it doesnt make a difference?), its simply going to the file show.html.erb and displaying that code instead (which results in an error due to properties not being passed etc).

I was wondering what i'm doing wrong, am i supposed to set something up in the routes.rb file?? (if this has anything to do with the issue?)

ActionController::Routing::Routes.draw do |map|
  map.resources :stores
  map.resources :stores

  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
end

Thanks a lot in advanced for开发者_开发知识库 any assistance as this is my first Ruby on Rails project


If you'd like to add a search action you'd want to set your routes file like this:

ActionController::Routing::Routes.draw do |map|
  map.resources :stores, :collection => { :search => :get }

  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
end

I would stick with naming the file search.html.erb although search.rhtml will work too. This is a good guide for routing in rails and here's the section that specifically applies to this answer.


Trying to answer each question:

  1. You have a duplicate map.resources :stores, one is enough.

  2. Yes you are correct http://localhost:3000/stores/search will load search.html.erb (better to name it that way to follow coventions) (I don't see the code from your controller but as you seems in the process of learning rails I assume you did not tweak the controller action with respond_to)

  3. It should not go to the show.html.erb view. Can you show us your StoresController?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜