RJS problem

Hi,

I’m implementing a “digg-like” page, that once you digg. The score for
each item will dynamically reflect your current action +1 .

I am not sure what’s
In the controller I have an action responsible for increase of the
score.It has a corresponding rjs in view.

def arouse
@p=Product.find(params[:id])
@list=List.find_favolist(session[:user_id])
@li=LineItem.findaddeditem(@p.id,@list.id)
[email protected]?
puts fair

if fair
puts ‘success’
@p.popular_score +=1
@p.save
puts “add”
@li = LineItem.new
@li.product_id =params[:id]
@li.list_id [email protected]
@li.likeornot =1
@li.created_at = Time.now
puts “line”
@li.save
redirect_to_index(“推文成功”) --> never worked, why?

else
redirect_to_index(“一人只有一票唷”) --> never worked, why?

end

end

In the view, I have a div displaying the score.

            <% if product ==@p %>
<div id="current_product">
<%= render(:partial => "score", :object => @p) %>
<% else %>
<div class="score">

<%= product.popular_score %>
<% end %> </div>

In arouse.rjs

page[:current_product].replace_html :partial => ‘score’, :object => @p

In _score.rhtml

<%= @p.popular_score %>

These are pretty much the setting.
But it just does not update the new score as I call the arouse with
form_remote_tag.
Is there anything I’m missing here?

Any suggestion and ideas are high welcomed.

Abon

On 1/28/07, Bontina C. [email protected] wrote:


being passed back to the page from your RJS. The following post will
This is what I got.
C:/INSTAN~1/rails_apps/test/config/…/app/views/admin/arouse.rjs:1:
href=“#”

C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:307:in
`render_without_benchmark'
C:/INSTAN~1/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/session_management.rb:117:in
`process_client'
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:625:in
`run'
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:292:in
`render' C:/INSTAN~1/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
`perform_action_without_rescue'
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in
`run'
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:625:in
`run'
  attributes:     name: !binary |      

Thanks

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

>

You might try the older syntax of:

page.replace_html ‘current_product’, :partial => ‘score’, :object => @p

There are other issues too. You are assigningg @p to the implicit
local variable score in the partial which you never use. So assigning
:object => @p is not needed according to the code in your partial.
This wouldn’t cause the problem your seeing though.


Zack C.
http://depixelate.com

On 1/28/07, Bontina C. [email protected] wrote:

def arouse
puts “add”
redirect_to_index(“Ò»ÈËÖ»ÓÐһƱࡔ) → never worked, why?
<% else %>

Abon


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

Bontina,

Try page[“current_product”].replace_html …

I don’t think the symbol form will work. Also check the javascript
being passed back to the page from your RJS. The following post will
show you how:
http://www.railsweenie.com/forums/2/topics/785

Hope this helps.


Zack C.
http://depixelate.com

Zack C. wrote:

On 1/28/07, Bontina C. [email protected] wrote:

def arouse
puts “add”
redirect_to_index(“һ��ֻ��һƱ�”) → never worked, why?
<% else %>

Abon


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

Bontina,

Try page[“current_product”].replace_html …

I don’t think the symbol form will work. Also check the javascript
being passed back to the page from your RJS. The following post will
show you how:
http://www.railsweenie.com/forums/2/topics/785

Hope this helps.


Zack C.
http://depixelate.com

I tried the syntax you suggested and added the debig tool.
This is what I got.
http status: 500

  Action Controller: Exception caught 
 body { background-color: #fff; color: #333; } body, p, ol, ul, 
td { font-family: verdana, arial, helvetica, sans-serif; font-size: 
13px; line-height: 18px; } pre { background-color: #eee; padding: 10px; 
font-size: 11px; } a { color: #000; } a:visited { color: #666; } a:hover 
{ color: #fff; background-color:#000; }    

SyntaxError in Admin#arouse

Showing
app/views/admin/arouse.rjs where line #1 raised:

compile error 
C:/INSTAN~1/rails_apps/test/config/../app/views/admin/arouse.rjs:1: 
Invalid char `\357' in expression 
C:/INSTAN~1/rails_apps/test/config/../app/views/admin/arouse.rjs:1: 
Invalid char `\273' in expression 
C:/INSTAN~1/rails_apps/test/config/../app/views/admin/arouse.rjs:1: 
Invalid char `\277' in expression

Extracted source

(around line #1):

1:
page["current_product"].replace_html :partial => ‘score’,
:object => @p

Trace of template inclusion:
/app/views/admin/arouse.rjs

RAILS_ROOT:
C:/INSTAN~1/rails_apps/test/config/…

Application Trace | Framework Trace | Full Trace

#{RAILS_ROOT}/app/views/admin/arouse.rjs:3:in 
`compile_template'
<div id="Framework-Trace"

style=“display: none;”>

C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:307:in 
`compile_and_render_template' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:292:in 
`render_template' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:251:in 
`render_file' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:726:in 
`render_file' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:648:in 
`render_with_no_layout' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/layout.rb:253:in 
`render_without_benchmark' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in 
`render' C:/INSTAN~1/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in 
`render' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:942:in 
`perform_action_without_filters' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:368:in 
`perform_action_without_benchmark' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in 
`perform_action_without_rescue' 
C:/INSTAN~1/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in 
`perform_action_without_rescue' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/rescue.rb:82:in 
`perform_action' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in 
`send' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in 
`process_without_filters' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:377:in 
`process_without_session_management_support' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/session_management.rb:117:in 
`process' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in 
`dispatch' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel/rails.rb:73:in 
`process' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:551:in 
`process_client' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:550:in 
`each' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:550:in 
`process_client' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:636:in 
`run' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:636:in 
`initialize' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:636:in 
`new' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:636:in 
`run' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:625:in 
`initialize' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:625:in 
`new' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:625:in 
`run' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:956:in 
`run' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:955:in 
`each' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:955:in 
`run' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/bin/mongrel_rails:127:in 
`run' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel/command.rb:199:in 
`run' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/bin/mongrel_rails:235 
C:/INSTAN~1/ruby/bin/mongrel_rails:18:in `load' 
C:/INSTAN~1/ruby/bin/mongrel_rails:18
<div

id=“Full-Trace” style=“display: none;”>

#{RAILS_ROOT}/app/views/admin/arouse.rjs:3:in 
`compile_template' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:307:in 
`compile_and_render_template' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:292:in 
`render_template' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:251:in 
`render_file' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:726:in 
`render_file' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:648:in 
`render_with_no_layout' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/layout.rb:253:in 
`render_without_benchmark' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in 
`render' C:/INSTAN~1/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in 
`render' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:942:in 
`perform_action_without_filters' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:368:in 
`perform_action_without_benchmark' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in 
`perform_action_without_rescue' 
C:/INSTAN~1/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in 
`perform_action_without_rescue' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/rescue.rb:82:in 
`perform_action' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in 
`send' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in 
`process_without_filters' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:377:in 
`process_without_session_management_support' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/session_management.rb:117:in 
`process' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in 
`dispatch' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel/rails.rb:73:in 
`process' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:551:in 
`process_client' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:550:in 
`each' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:550:in 
`process_client' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:636:in 
`run' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:636:in 
`initialize' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:636:in 
`new' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:636:in 
`run' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:625:in 
`initialize' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:625:in 
`new' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:625:in 
`run' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:956:in 
`run' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:955:in 
`each' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:955:in 
`run' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/bin/mongrel_rails:127:in 
`run' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel/command.rb:199:in 
`run' 
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/bin/mongrel_rails:235 
C:/INSTAN~1/ruby/bin/mongrel_rails:18:in `load' 
C:/INSTAN~1/ruby/bin/mongrel_rails:18
<h2

style=“margin-top: 30px”>Request

Parameters:
{"commit"=>"\346\216\250",
"id"=>"64"}

Show session dump

— :user_id: 1 :basket:
!ruby/object:Basket   items: [] :list: &id001 !ruby/object:List
  attributes:     name: !binary |      
5b6p5Y+k6aKo     id: "15"     user_id:
"1"     created_at: 2007-01-21 10:56:46  
errors: !ruby/object:ActiveRecord::Errors     base: *id001
    errors: {} flash: !map:ActionController::Flash::FlashHash
{}

Response


Headers: {"cookie"=>[],
"Cache-Control"=>"no-cache"}

Any furthur hint?

Thanks

On 1/28/07, Bontina C. [email protected] wrote:

<p>

I got the the right div updated in the html source.
But still I did not see any change on the web page.
Any idea what’s going wrong?
Thanks


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

page[:score#{@p.id}] will not give you what you want.

Try page[“score#{@p.id}”] to get the substitution working right. The
reason your not seeing anything is because of the error in your RJS
syntax. That’s why the ajax debugging shows those errors (from your
last post).

Also, did you try this syntax?

page.replace_html “score#{@p.id}”, :partial => ‘score’, :object => @p


Zack C.
http://depixelate.com

Try page[“score#{@p.id}”] to get the substitution working right. The
reason your not seeing anything is because of the error in your RJS
syntax. That’s why the ajax debugging shows those errors (from your
last post).

Also, did you try this syntax?

page.replace_html “score#{@p.id}”, :partial => ‘score’, :object => @p


Zack C.
http://depixelate.com

COOL It works for page[“score#{@p.id}”]
So the syntax I used is the older version?

I change the view to

<% for product in @products %>

<tr valign="top" class="<%= cycle('list-line-odd', 'list-line-even') 

%>">

  <td>
    <img class="list-image" src="<%= product.image_url1 %>"/>
<p>
<div class="score">
    <div id="score<%= product.id%>">
<%= product.popular_score %>
</div></div></p>
  </td>

in arouse.rjs
page[:score#{@p.id}].replace_html :partial => ‘score’, :object => @p

and from the ajax debug tool.
I got the the right div updated in the html source.
But still I did not see any change on the web page.
Any idea what’s going wrong?
Thanks