2016-05-29 23 views
0

So habe ich Kopf mit Ding stundenlang zugeschlagen nicht sicher, wohin ich gehen soll. Ich versuche, eine teilweise _show.html.haml innerhalb meiner index.html.haml zu rendern. Allerdings habe ich weiterhin Probleme damit, dass die Locals nicht geladen werden, obwohl sie beim Rendern deklariert wurden.Schienen AJAX Anfrage für teilweise wird nicht geladen Einheimischen trotz der Zuweisung sie

Dies ist mein Controller.

def show 
    @table = params["id"] 
    @bank = Bank.find(params["bank_id"]) 
    @table_contents = @bank.table_config.as_json.first[1][@table] 
    respond_to do |format| 
    format.js {render :partial => 'manage/table_configs/show', locals: { table: @table, table_contents: @table_contents}} 
    end 
end 

Dies ist Index.html.haml

#all-tables 
    %h1 Table Configurations 
    %br/ 
    %table#table_configs_table.pretty 
    %tr 
     %th Table Name 
    %tbody 
     - @tables.each do |table| 
     %tr 
      %td= link_to table.titleize, manage_bank_table_config_path(@bank, table), remote: true 

#show-table 
    %h2 Show 

:javascript 
    $('#show-table').html('#{escape_javascript(render(partial: "manage/table_configs/show", :locals => {:table => @table, :table_contents => @table_contents, :bank => @bank}))}'); 

Das ist mein Teil ist, dass ich diesen Fehler zu machen, dass ich versuche, hält zurück. undefined method 'titleize' for nil:NilClass

_show.html.haml

%h1= table.titleize 
%br/ 
%table.table.table-striped.table-hover.pretty 
    %tr 
    %th Column Name 
    %th Column State 
    %tbody 
    - table_contents.each do |key, value| 
     %tr 
     %td=key.to_s.titleize 
     %td=value.values.first.to_s.titleize 
%br/ 
=link_to "Edit Table", edit_manage_bank_table_config_path(@bank, table), class: "btn btn-sm" 
=link_to "All Tables", manage_bank_table_configs_path(@bank), class: "btn btn-sm" 

Jede Hilfe herauszufinden, warum dies sehr geschätzt werden würde geschieht.

Danke!

EDIT

Ich möchte auch hinzufügen, dass dies ohne AJAX funktioniert gut

+0

Willst du wirklich value.values.to_s und nicht nur value.to_s ... In der Show teilweise? – Anand

+0

'@ tables' ist nirgends deklariert, daher ist es standardmäßig Null. Ich sehe '@ table' deklariert, aber nicht' @ tables' –

+0

'@ tables' ist in meinem Index-Controller deklariert –

Antwort

0

sollten Sie die Vorlage außerhalb js erste

<% compiled_template = escape_javascript(render(partial: "manage/table_configs/show", :locals => {:table => @table, :table_contents => @table_contents, :bank => @bank}))%>

dann die kompilierte mit Jquery wie so hinzufügen kompilieren

$('#show-table').html("#{compiled_template}")