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: [code] <td><%= link_to ''Show'', project%></td> [/code] ...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: [code] <td><%= link_to ''Edit'', edit_project_path(project) %></td> [/code] 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 :). -- Posted via http://www.ruby-forum.com/.
On Jun 12, 9:30 pm, Mik Ben <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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: > > [code] <td><%= link_to ''Show'', project%></td> [/code] > > ...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: > > [code] <td><%= link_to ''Edit'', edit_project_path(project) %></td> > [/code] > > 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.> > 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 :(. >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 again for your time :). > -- > Posted viahttp://www.ruby-forum.com/.
> 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 " ) ? > > FredThanks for the help Fred, Hmmm...the produced HTML reads as follows: <tr onmouseover="ChangeColor(this, true);" onmouseout="ChangeColor(this, false);" onclick="new Ajax.Request(''/projects/1'', {asynchronous:true, evalScripts:true, parameters:''authenticity_token='' + encodeURIComponent(''EFK4UoM20XdzwDeneOTmVqtQYqG3Lgp+9swBrULFUsw='')});"> 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. -- Posted via http://www.ruby-forum.com/.