Forum: Ruby on Rails A question about ajax

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Zhao Y. (Guest)
on 2008-12-30 15:12
I defines a partial see below:
<%=
  puts @project.version
  text_field_tag "project_version", @project.version
%>

I want the project version update-to-date. The first line can print the
correct version value but the text field doesn't refresh to the new
version.
Vishwanath N. (Guest)
on 2008-12-30 17:39
(Received via mailing list)
Hi,

First of all, if you want to use puts in your views, use <% %> tags
rather
than <%= %> tags.
Secondly, if you load your partials once you have your data
object(@project)
with appropriate value your page should display the same.
But if you change the value of @project.version after the partial is
loaded,
it would not be reflected on the page until you reload the particular
div
which has the text field tag with the partial.

-NAYAK

On Tue, Dec 30, 2008 at 6:42 PM, Zhao Yi
Phlip (Guest)
on 2008-12-30 20:20
(Received via mailing list)
NAYAK wrote:

> First of all, if you want to use puts in your views, use <% %> tags
> rather than <%= %> tags.

>     I defines a partial see below:
>     <%=
>      puts @project.version
>      text_field_tag "project_version", @project.version
>     %>

The above will puts the @project.version to the STDOUT stream, then will
return
the text_field_tag into the <%= %> location.

This is a subtle hair to split (and 'p' is more useful than 'puts'
there), but
debugging out of the top of a <%= %>, while expressing its last line, is
very
common...

--
   Phlip
Zhao Y. (Guest)
on 2008-12-31 04:30
Vishwanath Nayak wrote:
> Hi,
>
> First of all, if you want to use puts in your views, use <% %> tags
> rather
> than <%= %> tags.
> Secondly, if you load your partials once you have your data
> object(@project)
> with appropriate value your page should display the same.
> But if you change the value of @project.version after the partial is
> loaded,
> it would not be reflected on the page until you reload the particular
> div
> which has the text field tag with the partial.
>
> -NAYAK
>
> On Tue, Dec 30, 2008 at 6:42 PM, Zhao Yi

Hi,

This is my controller code:

def update_project_selection

   @project = Project.find(:all,:conditions=>"name='#{selected_project}'
")
   render :partial => "project_version", :layout=>false
end

I update the @project object before load the partial. Why does the page
display the same value?

Below is the view page:

<%=
        select_tag:project_selection,options_for_select(@project_names)
%>

<%=
  observe_field :project_selection,
    :frequency => 0.5,
    :update => 'ajaxWrapper',
    :url => {:action => 'update_project_selection'},
    :with => "'project_selection='+encodeURIComponent(value)"
%>
Zhao Y. (Guest)
on 2008-12-31 06:30
I know what the problem. I set up a wrong update value in observe_field
element.
This topic is locked and can not be replied to.