small medium large xlarge

Generic-user-small
25 Aug 2008, 14:38
Tan YL (19 posts)

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 %> <%= 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” )

Generic-user-small
25 Aug 2008, 20:12
Tan YL (19 posts)

UPDATE: solved 1 & 3 need an answer on 2 though

Generic-user-small
26 Aug 2008, 00:47
David John Porter (12 posts)

Always nice to give feedback on the solved issues, so it helps other people ! cheers, Dave

Generic-user-small
26 Aug 2008, 02:31
Tan YL (19 posts)

nothing is wrong with the code. i made the noob mistake of putting the function under private

You must be logged in to comment