Browse the Ruby on Rails Community.

You are here: Forums Ask a Rails expert link_to image_tag problem...

Replytotopic

link_to image_tag problem

Posted in Forums : Ask a Rails expert

 
Profile

Authority 0
Posting Rating 14
Sign in to rate this post

Hello

In a page of my rails application I have the following code:

...
<%= text_field_tag( valconfig.id.to_i.to_s, valconfig.value, :size =>50 ) %>
...

As you can see, I am creating a text_field_tag with a dynamic ID.
Now I would like to be capable of sending the value of this text_field_tag.
How can I do that? Is there a way to do this??

I tried like the following but it dont work…

<%= link_to image_tag(“ok.jpg”, :border=>0), :controller => ‘entry’, :action => ‘setconfig’, :before => ‘busyMousePointer()’, :id => valconfig.id.to_i.to_s, :value => $F(valconfig.id.to_i.to_s), :only_path => false %>

The problem is that the ID of the text_field_tag is dynamically generated (and it must be)...

Thanks
regards

 
Profile

Authority 0
Posting Rating 14
Sign in to rate this post

I’m still not have found the solution for my problem…
Anyone can help?

 
Me

Authority 62
Posting Rating 100
Sign in to rate this post

Does the id really need to be dynamic or do you just need a dynamic name? Because in my experience, you hardly ever need dynamic ids like this.
Other than that, you could probably give the text field a CSS class and then do something like $F($$(‘input.yourClass’).first).

Maybe that helps.

 
N739949849_5167

Authority 12
Posting Rating 98
Sign in to rate this post

Try generating the url at the onclick event and redirecting via location.href:

<%= link_to image_tag(“ok.jpg”, :border => 0), ”#”, :onclick => “location.href = ’/entry/#{valconfig.id.to_s}/setconfig?value=’ + $F(’#{valconfig.id.to_s}’);” %>

Hope that works.

 
Profile

Authority 0
Posting Rating 14
Sign in to rate this post

Tanks for your help.

I’m gonna try the location.href solution.

Thanks.

Best regards.

Replytotopic

Other Recent Topics

Ask a Rails expert : json gem error

Ask a Rails expert : Problem with break

Ask a Rails expert : activesupport string first method error

Ask a Rails expert : url_for broken ?

Ask a Rails expert : map.routes.rb pls help

Ask a Rails expert : how to h tag in controller

Ask a Rails expert : Problem with Restful routing and partial form

Ask a Rails expert : will_paginate, search and ajax

Ask a Rails expert : captcha

Ask a Rails expert : Mass Deletes in Admin Section

Formatting Help
  • *bold*       _italics_      
    bq. (quotes)
  • "DSC":http://www.dsc.net
  • * or # (lists)
or cancel