Problems with link_to_remote

Hi,

I have been trying and searching for so long....... I have a label, a
text field and a link_to_remote link.

In the rhtml, it looks like this:

<tr>
<div class="abc">
<td style="width: 374px;"><label>Item 0</label></td>
<td style="width: 219px;"><%= n.text_field :display_bin_txt %> <%=
link_to_remote( "add", :update => "abc", :url =>{ :action => :add_item
}, :position => "bottom") %></td>
</div>
</tr>

When I click the link, a new label with the number incremented, Item 1
and a new text field will appear below the previous label, Item 0 and
text field. Can anyone tell me how can I acheive that?

Thanks

You cannot put a div inside a table row. It is not working because you’ve used the class attribute on the div.

Change class to id and get rid of the div, and set the id attribute on the tr tag.

user splash wrote:

Ryan Bigg wrote:

You cannot put a div inside a table row. It is not working because
you've
used the class attribute on the div.

Change class to id and get rid of the div, and set the id attribute on
the
tr tag.

--
Ryan Bigg
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

Hi,

I missed out a question. As Ryan Bigg said, I can't put a div inside a
table row. How can I display the things i want to display below that
row, the row with the original label and text field?

link_to_remote does not support :position.

Could you explain in more detail what you’re trying to do? Your descriptions are extremely vague and I cannot make sense of them.

Can you show us the code of that page please?

Ryan Bigg wrote:

link_to_remote does not support :position.

Could you explain in more detail what you're trying to do? Your
descriptions
are extremely vague and I cannot make sense of them.

Can you show us the code of that page please?

Hi,

What I am trying to do is to create an link that adds a new label and
text field when i click it.

Example:
<div id="content">
<% form_for :item, :url => { :action => :save_item}, :html => { :id =>
"item" } do |n| %>
  <table style="width: 685px; height: 171px;">
    <tbody>
      <tr>
        <td style="width: 374px;"><label>Item 0</label></td>
        <td style="width: 219px;"><%= n.text_field :item %> <%=
link_to_remote( "add", :update => "content", :url =>{ :action =>
:add_item }, :position => "bottom") %></td>

    </tr>
    <tr>
      <td style="width: 209px;">
        <div id="button">
    <p><%= link_to_function 'Previous', "$('item').submit()" -%></p>
        </div>
  </td>
      </tr>
    </tbody>
  </table>
<% end %>
</div>

After I click the link, "add", I will get the following result:

Item 0 text field
Item 1 text field add(this is a link)
   .
   .
   .

When the link is being clicked, another label and text field will be
added to the table, the number beside "Item" will increment and the
link, "add" will be next to the new added row.

I am not sure how can I achieve that. I hope the above explaination is
clear enough. Can someone please help me ?

Thanks

What I am trying to do is to create an link that adds a new label and
text field when i click it.

Example:
<div id="content">
<% form_for :item, :url => { :action => :save_item}, :html => { :id =>
"item" } do |n| %>
  <table style="width: 685px; height: 171px;">
    <tbody>
      <tr>
        <td style="width: 374px;"><label>Item 0</label></td>
        <td style="width: 219px;"><%= n.text_field :item %> <%=
link_to_remote( "add", :update => "content", :url =>{ :action =>
:add_item }, :position => "bottom") %></td>

    </tr>
    <tr>
      <td style="width: 209px;">
        <div id="button">
    <p><%= link_to_function 'Previous', "$('item').submit()" -%></p>
        </div>
  </td>
      </tr>
    </tbody>
  </table>
<% end %>
</div>

After I click the link, "add", I will get the following result:

Item 0 text field
Item 1 text field add(this is a link)
   .
   .
   .

When the link is being clicked, another label and text field will be
added to the table, the number beside "Item" will increment and the

Sorry I misssed out my controller.

In my controller:

def add_item
         render(:inline => %{<tr>
      <td style="width: 374px;"><label>TEXT FOR BIN CODE 1</label></td>
      <td style="width: 219px;"><%= n.text_field :item %>
    </tr>})
  end

When I click the link, I got this error, undefined local variable or
method `n' for #<#<Class:0x482c428>:0x482c400>. When I take away the n,
I got this error, wrong number of arguments (1 for 2). Where did I go
wrong and adding on to the previous questions, how can I display the
things that will show after I click the link in the correct place, which
is under the td tag of the orginal?

Sorry I misssed out my controller.

In my controller:

def add_item
         render(:inline => %{<tr>
      <td style="width: 374px;"><label>TEXT FOR BIN CODE 1</label></td>
      <td style="width: 219px;"><%= n.text_field :item %>
    </tr>})
  end

When I click the link, I got this error, undefined local variable or
method `n' for #<#<Class:0x482c428>:0x482c400>. When I take away the n,
I got this error, wrong number of arguments (1 for 2). Where did I go
wrong and adding on to the previous questions, how can I display the
things that will show after I click the link in the correct place, which
is under the td tag of the orginal?

Hi,
Can anyone please help me with the above two posting's questions?

Thank you

You posted 1 hour ago.

Do not expect a reply so quickly.

Why is it no one asking questions on here ever seems to bother reading a
programming book.

The var 'n' does not exist. HTTP is stateless. It has no f*cking idea
you rendered the form with "form_for do |n|" all it knows is what comes
in the params object and no you can't pass 'n' in the request.

this:

link_to_remote does not support :position.

Actually it does (but it only has meaning if you're updating a
particular element only (rather than using rjs)

Fred

# the form

<div id="content">
  <% form_for :item, :url => { :action => :save_item}, :html => { :id =>
"item" } do |n| %>
    <label>Item 0</label></td>
    <%= n.text_field :item %>
    <%= link_to_remote( "add", :update => "button", :url =>{ :action =>
:add_item }, :position => "above") %></td>
    <div id="button">
      <p><%= link_to_function 'Previous', "$('item').submit()" -%></p>
    </div>
  <% end %>
</div>

====================================================

use anything but a table to wrap that markup and you should be fine.
Though it would be better to strip down that link_to_remote and push the
extra stuff into the partial to work a rjs

Hi,
Thanks. It works. But there is a problem. I have no idea how to loop
this. Can anyone give me some clue?

loop this?

Keynan Pratt wrote:

loop this?

Yup. I have tried using session. Like this:

<% session[:count] ||= 1 %>
<tr>
<td style="width: 374px;"><label>Item <%= session[:count]
%></label></td>
<td style="width: 219px;"><%= text_field :item, :item %></td>
</tr>
<% session[:count] += 1 %>

It is the right way?

Keynan Pratt wrote:

loop this?

Yup. I have tried using session. Like this:

<% session[:count] ||= 1 %>
<tr>
<td style="width: 374px;"><label>Item <%= session[:count]
%></label></td>
<td style="width: 219px;"><%= text_field :item, :item %></td>
</tr>
<% session[:count] += 1 %>

It is the right way?

Almost certainly not. What are you looping over?

Fred

Frederick Cheung wrote:

I believe what Fred is asking is "WTF?"

Why do you need to loop at all?

Keynan Pratt wrote:

I believe what Fred is asking is "WTF?"

Why do you need to loop at all?

Hi,

I loop to get the incementing number for Item some_number. I tried many
way to get this counter thing right. Please direct me to the right path
if I am wrong.
How do I or should I do this counter?

Thanks

Keynan Pratt wrote:

I believe what Fred is asking is "WTF?"

Why do you need to loop at all?

Hi,

I loop to get the incementing number for Item some_number. I tried
many
way to get this counter thing right. Please direct me to the right
path
if I am wrong.
How do I or should I do this counter?

Why involve the session? If you want to do something 5 times then it's
as simple as

<% 5.times.do |index| %>
...
<% end %>

Fred

Fred note the line:

way to get this counter thing right. Please direct me to the right

We are clearly dealing with someone with out the faintest concept. for
simple things like this we must not give answers only ask the right
questions

Frederick Cheung wrote:

Why involve the session? If you want to do something 5 times then it's
as simple as

<% 5.times.do |index| %>
...
<% end %>

Fred

But won't that print the stuff inside the <% 5.times do |index| %> 5
times when the link is clicked? I only want the stuff to be printed out
once with the number incremented each time the link is clicked.

Example:
Item 0 when link is clicked,
Item 1 when link is clicked,
Item 2 and so on.