Unusual RJS error

Posted by rrb on Stack Overflow See other posts from Stack Overflow or by rrb
Published on 2011-01-03T11:24:18Z Indexed on 2011/01/03 13:53 UTC
Read the original article Hit count: 188

Filed under:

Hi, I am getting the following error in my RoR application: RJS error:

TypeError: element is null

Element.update("notice", "Comment Posted"); Element.update("allcomments", "\n\n\n \n\n waht now?\n\n \n\n \n\n \n\n asdfasdfa\n \n\n \n\n asdfasdf\n \n\n\n\n
\n");

But when I hit the refresh button, I can see my partial updated.

Here's my code:

show_comments View:

<table>
<% comments.each do |my_comment| %>
  <tr>

    <td><%=h my_comment.comment%></td>
  </tr>
<% end %>
</table>

show View:

<div class="wrapper">
    <div class="rescale">
      <div class="img-main">
        <%= image_tag @deal.photo.url %>
      </div>

    </div>
    <div class="description">
    <p class ="description_content">
      <%=h @deal.description %>
    </p>
    </div>
    </div>
    <p>
      <b>Category:</b>
      <%=h @deal.category %>
    </p>

    <p>
      <b>Base price:</b>
      <%=h @deal.base_price %>
    </p>

    <%#*<p>%>
      <%#*<b>Discount:</b>%>
      <%#=h @deal.discount %>
    <%#*</p>%>

    <%= link_to 'Edit', edit_deal_path(@deal) %> |
    <%= link_to 'Back', deals_path %>

    <p>
      <%= render :partial=>'deal_comments', :locals=>{
          :comments=>Comment.new(:deal_id=>@deal.id)} %>
    </p>
    <div id="allcomments">
      <%=  render :partial=>'show_comments', :locals=>{
        :comments=>Comment.find(@deal.comments)} %>
    </div>

Controller:

    def create
        @comment = Comment.new(params[:comment])
        render :update do |page|
          if @comment.save
            page.replace_html 'notice', 'Comment Posted'
          else
            page.replace_html 'notice', 'Something went wrong'
          end
          page.replace_html 'allcomments', :partial=> 'deals/show_comments',
            :locals=>{:comments=> @comment.deal.comments}
        end
  end

  def show_comments
    @deal = Deal.find(params[:deal_id])
    render :partial=> "deals/show_comments", :locals=>{:comments=>@deal.comments}
  end
end

© Stack Overflow or respective owner

Related posts about ruby-on-rails