0
我已經創建了一個showwhtml.erb vew,其中有一個複選框列表存在我想要當複選框cliked命名爲Generate的行動是執行,然後渲染一個部分內這show.html.erb我使用作用電纜,但未能如願 這裏試過是我Show.html.erbRails 5行動電纜不工作
<%= @files.each do |key,value|%>
<div class="subdir">
<%= check_box_tag(key, value, false, data: {remote: true, method: :post, url: generate_repository_path }) %>
<%= label_tag key%>
</div>
<br>
<%end%>
生成方法
def generate
request.POST.each do |key,value|
@filename=key
@path= value
end
@id=params[:id]
@file=Hash.new
if File.directory?(@path)
Dir.chdir("#{@path}")
Dir.glob("*").each do |entries|
@file[entries]="#{@path}/entries"
puts "#{entries}"
end
render(partial: 'operations/dir',object: @file)
else
puts "It is a file"
end
end
這裏是我的部分
<%= @file.each do |key,value|%>
<%= check_box_tag(key, value, false, data: {remote: true, method: :post, class: "checkbox", url: generate_repository_path }) %>
<%= label_tag key%>
<br>
<%end%>
這裏是我的operations.coffee文件
App.operations = App.cable.subscriptions.create "OperationsChannel",
connected: ->
# Called when the subscription is ready for use on the server
disconnected: ->
# Called when the subscription has been terminated by the server
received: (data) ->
# Called when there's incoming data on the websocket for this channel
$(".subdir").prepend(data);
和Operations_channel.erb
class OperationsChannel < ApplicationCable::Channel
def subscribed
stream_from "operations"
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
end
這裏是從複選框日誌
Started GET "/cable" for 127.0.0.1 at 2017-03-03 14:37:37 +0530
Started GET "/cable/" [WebSocket] for 127.0.0.1 at 2017-03-03 14:37:37 +0530
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: keep-alive, Upgrade, HTTP_UPGRADE: websocket)
OperationsChannel is transmitting the subscription confirmation
OperationsChannel is streaming from operations
Started POST "/repositories/12/generate" for 127.0.0.1 at 2017-03-03 14:37:42 +0530
Processing by RepositoriesController#generate as JS
Parameters: {"sections"=>"/home/sifat/directory/public/system/repositories
/uploads/extract/12/resume/sections", "id"=>"12"}
skills.tex
work.tex
projects.tex
bio.tex
education.tex
communication.tex
Rendered operations/_dir.html.erb (1.3ms)
Completed 200 OK in 6ms (Views: 4.1ms | ActiveRecord: 0.0ms)
我能夠調用的方法產生而且呈現partial _dir.html.erb,但不會在show.html.erb中更改或顯示。