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:

Item 0 <%= n.text_field :display_bin_txt %> <%= link_to_remote( "add", :update => "abc", :url =>{ :action => :add_item }, :position => "bottom") %>

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.

On Jan 24, 2008 1:26 PM, user splash [email protected]
wrote:

Item 0

Thanks

Posted via http://www.ruby-forum.com/.


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

Ryan B. 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 B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

Hi,

oh…After changing the class to id it I manage to display some text. As
I use this codes in the controller to test out the link.

def add_item
render_text “

Item ” + DateTime.now.to_s + “


end

But there are still some problems and questions I want to ask. Even
though in the link_to_remote, I set the text to be displayed after the
original label and text field by using :position => “bottom”, the text
is being displayed on top of the original one. Can someone tell me why
or what happened here?

The other question is 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. How do I achieve that?

Thanks

user splash wrote:

Ryan B. 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 B.
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 B. 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?

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

Example:

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

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 => %{


TEXT FOR BIN CODE 1
<%= n.text_field :item %>
})
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 => %{


TEXT FOR BIN CODE 1
<%= n.text_field :item %>
})
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

Ryan B. 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:

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

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

You posted 1 hour ago.

Do not expect a reply so quickly.

On Jan 24, 2008 5:29 PM, user splash [email protected]
wrote:

</tr>})

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

Thank you

Posted via http://www.ruby-forum.com/.


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

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:

def add_item
render(:inline => %{

TEXT FOR BIN CODE 1 <%= n.text_field :item %> }) end ============================================================ should be in a partial. MVC is a fundamental part of RAILS. That means no html in your controllers. Period.

As to your layout. lose the table it will only make this harder. Tables
are for tabular data ONLY.

You end up with:

===================================================
def add_item
render(:partial => ‘item_inputs’)
end

#item_inputs

Item <%= some_counter %>
<%= text_field :item, :item %>

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

the form

<% form_for :item, :url => { :action => :save_item}, :html => { :id => "item" } do |n| %> Item 0 <%= n.text_field :item %> <%= link_to_remote( "add", :update => "button", :url =>{ :action => :add_item }, :position => "above") %>

<%= link_to_function 'Previous', "$('item').submit()" -%>

<% end %>

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

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

On 24 Jan 2008, at 04:50, Ryan B. wrote:

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

<% form_for :item, :url => { :action => :save_item}, :html => { :id => "item" } do |n| %> Item 0 <%= n.text_field :item %> <%= link_to_remote( "add", :update => "button", :url =>{ :action => :add_item }, :position => "above") %>

<%= link_to_function 'Previous', "$('item').submit()" -%>

<% end %>

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

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?

On 24 Jan 2008, at 09:59, user splash wrote:

<%= text_field :item, :item %> <% session[:count] += 1 %>

It is the right way?

Almost certainly not. What are you looping over?

Fred

Keynan P. wrote:

loop this?

Yup. I have tried using session. Like this:

<% session[:count] ||= 1 %>

Item <%= session[:count] %> <%= text_field :item, :item %> <% session[:count] += 1 %>

It is the right way?

Frederick C. wrote:

On 24 Jan 2008, at 09:59, user splash wrote:

<%= text_field :item, :item %> <% session[:count] += 1 %>

It is the right way?

Almost certainly not. What are you looping over?

Fred

The text field. Am I heading to the right direction? Or should I loop
over the add link? And how do I do that?

Thanks

I believe what Fred is asking is “WTF?”

Why do you need to loop at all?

Keynan P. 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

On 24 Jan 2008, at 10:52, user splash wrote:

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