SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Controller Help

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Location
    Texas
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Controller Help

    Hello,

    I am trying to link from a relationship field back to its original controller so that it shows the clicked on page. I will try to explain this as best as I can. I have two models - Well and Customer. Each well has one customer which can be seen in the 'list' view. I want to be able to click any one of these customers and navigate to the corresponding 'show' for that customer.

    Here is what I have so far in my Well-list.rhtml
    Code Ruby:
    <td><%= link_to %Q{#{well.customer.name}}, {:controller => 'customers', :action => 'show', :id => 'well.customer.id' } %></td>

    Here is the code for the form that selects a customer for a well:
    Code Ruby:
    <p><label for="well_customer_id">Owner</label><br/>
    <%= select("well", "customer_id", Customer.find(:all).collect {|c| [c.name, c.id] }) %> 
    <%= link_to 'New Customer', :controller => 'customers', :action => 'new' %></p>

    Here is the method for show in my customer controller:
    Code Ruby:
    def show
        @customer = Customer.find(params[:id])   
      end

    Everything is working except that it is not producing the correct link. Everything is good until the 'id' part of the link where it simply puts 'well.customer.id' instead of the correct id#

    Please help! Thanks!

    Matt
    Web design is cool. Roll with it.

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code ruby:
    link_to well.customer.name, {:controller => 'customers', :action => 'show', :id => well.customer}

    Notes:

    [1] Removed &#37;Q{#{...}}
    [2] Removed the quotes around 'well.customer.id', and removed '.id'.

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Location
    Texas
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You da man! Awesome. Great fix. Thanks so much
    Web design is cool. Roll with it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •