开发者

Ruby on Rails 3, Changing Views

Im working with Rails 3.0.9 and Ruby 1.9.2.

I have a search page that will display a list of results in grid format. However, I want to be able to give the user an option to display them in list format.

Could anyone please advise me about how I can offer a change view option,and still keep the searc开发者_运维知识库h results?


As you have not specified where query is stored,

I will hope that in url, like example.com/search?query=mylookupstring

So in this case all we need is to place somewhere on a page, link_to search path and pass your query + some parameter back to controller to prepare new view

 <%= link_to "List", search_some_thing_path(:query=>params[:query],:list=>true) %>

nice & easy

Post your details if i show bad skills with telepathy today.

UPDATE:

Pay attention to params & url. Yours & my example. You shouldn't just copy

as your controller expects params[:search] not params[:query]

So fix error in you link_to & move_on!

PS Great tip to find out how rails really work is to use debugger.

You may attach it in view

<% debugger %> or in model/controller simply debugger

Don't forget to include debug gems in your Gemfile, smth like

group :development, :test do
  gem 'ruby-debug19'
end
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜