Quantcast
Channel: Pragmatic Forums | Posts by Tan YL
Viewing all articles
Browse latest Browse all 19

Is making a search page on the same page as the user page possible posted by Tan YL @ Mon, 25 Aug 2008 10:23:35 +0000

$
0
0

Hi,

Thanks to this book and the ruby community i am starting to build my app, however i am now stuck. I need to create a user page that can search and add objects to a cart

Step by step of how app should work:

1. User logins

2. on the side bar there is a search box where i search for objects
and the objects are displayed on the side after the search is
complete. then i add them to the cart which is in the main coloum.

side div #    # main div
  search #    #  cart
  item1  #    #  item1
   item2 #    #  item3
                 total amt:

Problem:

(1)because i am already logged into a user page the address on the browser
is stuck at the /panel/id of the user so when i try to use the side to
search i get errors as the routing for user is being superseded by the
side search routing. error i get is: Couldn’t find user without an ID

(2)i am not sure that routing using a show action and using the users id is the correct way to bring a user to his home page.

(3)When i use AJAX to create the left side, I am not sure that thinking_sphinx and will_paginate will work.

{trying to do it AJAX way code}
{{FORM}}

<% form_remote_tag :url => {:action => :search}, :method => “get” do
>
<label for="item_name"></label>
<
= text_field_tag(“query”, params[‘query’], :size => 20 ) >
<
= submit_tag “Search” %>

{{CONTROLLER}}

def search
     groceries_per_page = 4
@groceries = Groceries.search params[:query], {:page =>
params[:page], :per_page => groceries_per_page}
respond_to do |format|
        format.js
end
if request.xml_http_request?
                           render :partial => "search", :layout => false
                     end
end

{{PARTIAL}}

<% if @groceries == nil %> @groceries is nil
<% else %> <% for groceries in @groceries %>
groceries.name <% end %>

{{search.js.rjs}}

page.replace_html(“sgreplace”, :partial => “search” )


Viewing all articles
Browse latest Browse all 19

Trending Articles