Hi all,

I am quite new to Rails.

The code below loads a set of data from the database. When I click on
one of the item from db, it will load more details of same item from
database and display in the <div> next to it.

See listings below to see code snippet:

listing 1(search.html.erb)
--------------------------
[code]
<div class="row">
<div class="four columns">
<nav>
<ul class="list group">
<% @tbl_unique_traces.each do |tbl_trace| %>
<li>
<a data-remote="true" href="<%= trace_loader_url (tbl_trace)
%>?short_exchange_id=<%= tbl_trace.short_exchange_id %>">
<h6>
<%= tbl_trace.short_exchange_id %>
</h6>
<%= tbl_trace.short_exchange_id %></a></li>
</li>
<% end %>
</ul>
</nav>
</div>

<div id="loader_div" name="loader_div">
<% if @group_trace %>
<%= render(@group_trace) %>
<% end %>
</div>
</div>
[/code]


listing 2(trace_controller.rb)
------------------------------
[code]
def search
@tbl_unique_traces = TblTrace.find_by_sql("select top.....)

respond_to do |format|
format.html # show.html.erb
format.json { render :json => @tbl_unique_traces }
end
end

def loader
@group_trace = TblTrace.find_by_sql("select ........)

respond_to do |format|
format.html # loader.html.erb
format.js
format.json { render :json => @group_trace }
end
end
[/code]

listing 3(loader.js.erb)
-------------------------
[code]
$('#loader_div').html("<%=j render(@group_trace)%>");
[/code]


listing 4 (_group_trace.html.erb)
--------------------------------
[code]
<div class="eight columns">
<dl id="accordion" class="list-accordion">
<dt><span></span>view one</dt>
<dd>
<p>Data here</p>
</dd>
</dl>
</div>
[/code]

The problem is that, this codeline never get executed:

<% if @group_trace %>
<%= render(@group_trace) %>
<% end %>

And I can confirm that @group_trace has data in the trace_controller.

What can be the problem? Please help out.

Regards.

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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Javier Quarite at Feb 8, 2012 at 7:09 pm

    On Wed, Feb 8, 2012 at 2:00 PM, Lekkie Lekkie wrote:
    listing 3(loader.js.erb)
    -------------------------
    [code]
    $('#loader_div').html("<%=j render(@group_trace)%>");
    [/code]
    Is that a "j" after the = ??


    Javier Q.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Naira Kobo at Feb 9, 2012 at 7:18 am

    Javier Quarite wrote in post #1044799:
    On Wed, Feb 8, 2012 at 2:00 PM, Lekkie Lekkie wrote:


    listing 3(loader.js.erb)
    -------------------------
    [code]
    $('#loader_div').html("<%=j render(@group_trace)%>");
    [/code]
    Is that a "j" after the = ??


    Javier Q.
    Removed but still the same.

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

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Linus Pettersson at Feb 8, 2012 at 7:15 pm
    Well, you go here, right?
    yourapp.com/search ?

    Then the @group_trace is nil because it's not created until you run the
    loader action.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/ziUGfwYJGUQJ.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Naira Kobo at Feb 9, 2012 at 7:16 am

    Linus Pettersson wrote in post #1044801:
    Well, you go here, right?
    yourapp.com/search ?

    Then the @group_trace is nil because it's not created until you run the
    loader action.
    Does this mean the logic of this app is wrong, how else can I do this
    right?

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

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Linus Pettersson at Feb 9, 2012 at 7:49 pm
    Well, the code in the search view is executed when the view is rendered. It
    is not executed again when you inject the html using javascript.
    So the if @group_trace code is only executed when the search view is
    rendered and @group_trace is not created yet.


    What are you actually trying to achieve? What do you want to do with the if
    @group_trace code part? Why not just remove it? You're still adding the
    data by injecting the html using javascript.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/tN-N4eeOmnQJ.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Naira Kobo at Feb 13, 2012 at 9:06 am

    Linus Pettersson wrote in post #1045014:
    Well, the code in the search view is executed when the view is rendered.
    It
    is not executed again when you inject the html using javascript.
    So the if @group_trace code is only executed when the search view is
    rendered and @group_trace is not created yet.


    What are you actually trying to achieve? What do you want to do with the
    if
    @group_trace code part? Why not just remove it? You're still adding the
    data by injecting the html using javascript.
    If I remove it, it throws a nil object exception which basically means
    the object is empty.

    I just want to click on this link in search.html.erb:

    <a data-remote="true" href="<%= trace_loader_url (tbl_trace)
    %>?short_exchange_id=<%= tbl_trace.short_exchange_id %>">
    <h6>
    <%= tbl_trace.short_exchange_id %>
    </h6>
    <%= tbl_trace.short_exchange_id %></a>


    and it should load the data returned in trace_controller.rb:

    def loader
    @group_trace = TblTrace.find_by_sql("select top (1) * from tbl_traces
    where short_exchange_id = '" + params[:short_exchange_id] + "'
    order by created_on desc")


    and display in the div in seach.html.erb here:

    <div id="loader_div" name="loader_div">
    <% if @group_trace %>
    <%= render(@group_trace) %>
    <% end %>
    </div>

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

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Linus Pettersson at Feb 13, 2012 at 4:45 pm
    Yes, but the code in the search view is not executed again when the AJAX
    request is fired :)

    So, you have to do the check in your loader.js.erb and not the search view.
    Something like this should work:

    <% if @group_trace %>
    $('#loader_div').html("<%=j render(@group_trace)%>");
    <% end %>

    Cheers!

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/ikdirO2VujcJ.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Naira Kobo at Feb 14, 2012 at 1:28 pm

    Linus Pettersson wrote in post #1046510:
    Yes, but the code in the search view is not executed again when the AJAX
    request is fired :)

    So, you have to do the check in your loader.js.erb and not the search
    view.
    Something like this should work:

    <% if @group_trace %>
    $('#loader_div').html("<%=j render(@group_trace)%>");
    <% end %>

    Cheers!
    I tried this but I get this error

    Extracted source (around line #19):

    undefined method `model_name' for NilClass:Class

    18: <div id="loader_div" name="loader_div">
    19: <%= render(@grouptrace) %>
    20: </div>

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

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Dave Aronson at Feb 14, 2012 at 2:15 pm

    On Tue, Feb 14, 2012 at 08:28, Naira Kobo wrote:

    Extracted source (around line #19):

    undefined method `model_name' for NilClass:Class

    18:                     <div id="loader_div" name="loader_div">
    19:         <%= render(@grouptrace) %>
    20:       </div>
    This is telling you that @grouptrace is nil. You dropped the
    underscore from inside the name. (Minirant: This is one of the
    things I don't like about languages letting you reference undeclared
    variables. You can't tell "I deliberately haven't set it yet, so the
    fact that it's nil is significant" from a typo.)

    -Dave

    --
    Dave Aronson:  Available Cleared Ruby on Rails Freelancer
    (NoVa/DC/Remote) -- see www.DaveAronson.com, and blogs at
    www.Codosaur.us, www.Dare2XL.com, www.RecruitingRants.com

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 8, '12 at 7:00p
activeFeb 14, '12 at 2:15p
posts10
users4
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase