ruby - Rails 4: How to prevent jumping to index -
i new rails , coding first app.
created search name of tools model. it's passing params correctly (jumps/redirects/passes params) index of model. how can direct to tools#search site (site search form)?
a url overview:
http://localhost:3000/search # start http://localhost:3000/tools?utf8=%e2%9c%93&search=&commit=search # directed http://localhost:3000/search?utf8=%e2%9c%93&search=&commit=search # should direct
a code overview:
routes
get '/search' => 'tools#search'
tool model
# search def self.search(search) if search where(["title ?", "#{search}"]) else end end
tools controller
def search @tools = tool.search(params[:search]).order("created_at desc") end
search view (app/views/tools/search.html.haml)
= form_tag search_path, :method => 'post' = text_field_tag :search, params[:search] = submit_tag "search" - @tools.each |tool| = image_tag tool.cover_filename.url %h2= link_to tool.title, tool %p= tool.subtitle %p= link_to tool.user.try(:username), '/users/'+tool.user_id.to_s %p= tool.impressionist_count %p= link_to tool.get_upvotes.size, like_tool_path(tool), method: :get %p= link_to "favorite", favorite_tool_path(tool, type: "favorite"), method: :get %p= link_to "unfavorite", favorite_tool_path(tool, type: "unfavorite"), method: :get %p= link_to "edit", edit_tool_path(tool) %p= link_to 'http://ocubit.com/tools/'+tool.id.to_s %p= time_ago_in_words(tool.created_at)
thanks helpful replies, appreciated!
change tools_path
search_path
in view
= form_tag search_path, :method => 'get' = text_field_tag :search, params[:search] = submit_tag "search"
i suggest changing method post
form submission
Comments
Post a Comment