# A simple problem

**URL:** <https://www.ruby-forum.com/t/a-simple-problem/170152>\
**Category:** Rails\
**Created:** [June 12, 2009, 10:30pm UTC](https://www.ruby-forum.com/t/a-simple-problem/170152 "2009-06-12T22:30:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikben](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e95f7d/32.png) [@mikben](https://www.ruby-forum.com/u/mikben)\
**Post date:** [June 12, 2009, 10:30pm UTC](https://www.ruby-forum.com/t/a-simple-problem/170152/1 "2009-06-12T22:30:49Z")

</div>

Hey guys - thanks for reading this.

I’m trying to use the onclick event to redirect the user via a ruby  
function. The code is within a “view” html.erb file. The original  
table has an entry that works perfectly fine:

```auto
 <td><%= link_to 'Show', project%></td> 
```

…but I’d like for the user to be able to click anywhere on that row  
and be directed to the “show” page. If you’re feeling generous, can you  
also explain why, in this case, “project” suffices, while in this case:

` <td><%= link_to 'Edit', edit_project_path(project) %></td>
`

I say “edit\_project\_path(project)”? Where would this method be located?  
My attempt for the onclick event:

\<tr onmouseover="ChangeColor(this, true);" onmouseout="ChangeColor(this, false);" onclick="\<%= remote\_function( :url =\> { :controller =\> 'projects', :action =\> 'show', :id =\> project.id }) %\>;" [/code]

The ChangeColor methods are defined and function properly, but clicking  
the row does nothing :(.

Thanks again for your time :).

---

<div class="post-metadata">

**Author:** ![mikben](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e95f7d/32.png) [@mikben](https://www.ruby-forum.com/u/mikben)\
**Post date:** [June 12, 2009, 11:36pm UTC](https://www.ruby-forum.com/t/a-simple-problem/170152/2 "2009-06-12T23:36:24Z")

</div>

On Jun 12, 9:30 pm, Mik B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> also explain why, in this case, “project” suffices, while in this case:
> 
> ` <td><%= link_to 'Edit', edit_project_path(project) %></td>
> `
> 
> I say “edit\_project\_path(project)”? Where would this method be located?

This method is created for you by rails, based on your routes. There  
is another helper, project\_path that gives the path for the show  
action, but you don’t have to use that as link\_to assumes that’s what  
you want to do if you just pass it an active record object.

> 

What does your controller code look like ? Is the request made ? does  
this product syntactically correct html (eg it wouldn’t if the output  
from remote\_function contained a " ) ?

Fred

---

<div class="post-metadata">

**Author:** ![mikben](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e95f7d/32.png) [@mikben](https://www.ruby-forum.com/u/mikben)\
**Post date:** [June 13, 2009, 12:20am UTC](https://www.ruby-forum.com/t/a-simple-problem/170152/3 "2009-06-13T00:20:00Z")

</div>

> What does your controller code look like ? Is the request made ? does  
> this product syntactically correct html (eg it wouldn’t if the output  
> from remote\_function contained a " ) ?
> 
> Fred

Thanks for the help Fred,

Hmmm…the produced HTML reads as follows:

My controller code does contain a “show” def, which is requested in the  
“:action =\>” declaration. When the working link is clicked, the “show”  
def does the following correctly:

def show  
@project = Project.find(params[:id])

```
respond_to do |format|
  format.html # show.html.erb
  format.xml { render :xml => @project }
end

```

end

But the remote\_function does not.
