Thanks a lot, there was a problem in the list_per_customer template..it works now.
On Mon, Apr 11, 2011 at 3:10 AM, Frederick Cheung < [email protected]> wrote: > > > On Apr 10, 8:11 pm, RailsNewbie <[email protected]> wrote: > > I am new to Rails and have a simple problem where I am trying to pass > > a parameter from a view to another controller outside the scope...The > > model is about a Customer having multiple Prescriptions. The GET > > request is : /prescription/list_per_customer/2 > > > There's really not any difference between a link that will be routed > to the same controller and one that won't. > > > This is from the view of Customers : > > > > <%= link_to "Customers Prescription", :action => > > "list_per_customer", :controller => "prescription", :id => @customer.id > > %> > This is fine as long as their is a route backing this (the default one > will do if it exists) > > > > > This is from the other controller, PrescriptionController : > > > > def index > > @referred_customer=params[:id] > > end > > def list_per_customer > > @cust_prescriptions = > > Prescription.find_all_by_customer_id(@referred_customer) > > redirect_to :action => 'list_per_customer' > > end > > You haven't said what isn't working, but at the very least you need to > assign params[:id] to @referred_customer (although personally I find > that a bit misleading - it makes it sound like @referred_customer is a > customer object rather than just an id) and I doubt you want to > redirect - presumably you have a list_by_customer template that knows > how to display the prescriptions. > If you're new I'd also try using more of the rails conventions (eg > make prescriptions a nested resource (see the routing guide on > guides.rubyonrails.org for more info) > > Fred > > > > How can this be done with or without sessions ? Will appreciate very > > much if the complete code is provided for these two parts of the code > > in Customer->view.rhtml and Prescription->list_per_customer...thx > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

