У меня есть частичная функциональность «рассказать другу о чем-то». И я хочу сообщить пользователю, все ли в порядке, поэтому я возвращаюсь в контроллер, чтобы показать вспышки.Обратный рендер частичный и показать вспышки
Проблема в том, что я вижу вспышки через pry (отладчик), но на экране ничего не отображается.
Как показано ниже:
Поддеть Результаты:
** ВАЖНО: ** Рассказать другу это страница, которая открывается при нажатии на ссылку. Ссылка открывает страницу индекса, которая открывает частичную.
я пробовал разные вещи:
- возвращение делают: индекс
- визуализации: индекс
- перенаправлять
- ...
index.html.erb файл:
<!doctype html>
<html lang="nl">
<head>
<meta charset="utf-8" />
<title><%= t("share.index.header") %></title>
<!--[if lt IE 9]><script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<%= javascript_include_tag "application" %>
<%= stylesheet_link_tag "application", :media => "all" %>
<style>
body {
margin: 2em;
font: 14px/1em 'open-sans', sans-serif;
color: #333;
background: #eee;
}
h1 {
font-weight: normal;
color: #666;
}
p {
color: #666;
font-size: 12px;
margin: 0 0 3em 0;
}
p a {
color: #333;
text-decoration: none;
border-bottom: 1px dotted #666;
}
form {
position: relative;
}
.col-2 {
position: absolute;
top: 0; left: 25em;
}
label {
display: block;
margin: 0 0 2em 0;
}
strong {
font-weight: normal;
display: block;
margin: 0 0 .5em 0;
}
input[type=text] {
padding: 6px;
width: 25em;
border: 1px solid #ccc;
background: #fff;
}
input[type=submit] {
color: white;
font-size: 14px;
padding: .75em;
}
</style>
</head>
<body>
<div id="wrap">
<% if current_user %>
<%= render :partial => "signed_in_user" %>
<% else %>
<%= render :partial => "anonymous_user" %>
<% end %>
</div>
<script>
</script>
</body>
</html>
signed_in_user парциальное:
<script type="text/javascript"charset="UTF-8">
$(document).ready(function() {
$("#submitBtn").click(function() {
// Simple input Validation
var emailaddress = $("#email").val();
if(!validateEmail(emailaddress)) {
$("#validationerror").show();
return false;
};
});
function validateEmail($email) {
var emailReg = /^([\w-\.][email protected]([\w-]+\.)+[\w-]{2,4})?$/;
if ($email == ''){
return false;
} else {
if(!emailReg.test($email)) {
return false;
} else {
return true;
}
};
};
});
</script>
<!-- Why is this code not showing after return render -->
<!-- Why is this code not showing after return render -->
<!-- Why is this code not showing after return render -->
<p><%= flash[:notice] %></p>
<!-- Why is this code not showing after return render -->
<!-- Why is this code not showing after return render -->
<!-- Why is this code not showing after return render -->
<h1><%= t :header, :scope => [:share, :index] %></h1>
<p><%= t :link_to_page_html, :scope => [:share, :index], :link => link_to(truncate(job_url(params[:job_id]),length: 50, omission: '...'), job_path(params[:job_id])) %></p>
<%= form_tag(job_share_index_path(params[:job_id]), :method => "post", :id => "myform", :remote => true) do %>
<%= hidden_field_tag "guid", params[:job_id] %>
<div class="col-1">
<label>
<strong><%= t("share.index.name") %></strong>
<%= text_field_tag "fullname", "", :autofocus => "autofocus" %>
</label>
<label>
<strong><%= t("share.index.email") %></strong>
<%= content_tag(:p, t("share.index.valid_email") , :id => "validationerror", :class => 'small_label' , :style => "display: none;color: red; font-weight: bold;") %>
<%= text_field_tag "email", "", :placeholder => t("share.index.email_placeholder"), :id => "email" %>
</label>
</div> <!-- /.col-1 -->
<div class="col-2">
<label>
<strong><%= t("share.index.message") %></strong>
<%= text_area_tag "message", "", :style => "width: 370px; height: 175px;"%>
</label>
</div> <!-- /.col-1 -->
<%= submit_tag t("share.index.button"), :class => "medium button", :id => "submitBtn" %>
<% end %>
Доля контроллер
class ShareController < ApplicationController
def index
render :layout => false
end
def create
Sap.tell_a_friend(params[:fullname], params[:message], params[:guid], params[:email], api_params_for_user)
# respond_to do |format|
# format.html { redirect_to(job_share_index_path) }
# format.js
# end
flash[:notice] ="test"
return render :index
end
end
Я попробовал оба предложения и это мои изменения: https://gist.github.com/YOUConsulting/dee98438b387559825de Если я взглянуть на HTML через инспектировать элемент 2 р и 1 DIV пуст. Как показано на рисунке: https://www.evernote.com/shard/s314/sh/189ad800-8c37-48e2-80d1-e66bfada67bb/2998388d5780eb759dba324f7f728c3e Kr, Vince – Vinozio
Это довольно трудно следовать всем этот код, который у вас есть, может помочь более простой случай с воспроизведением. Тем не менее, вы действительно запрашиваете действие «create» в любом месте? Или вы просто показываете действие 'index', которое не имеет никаких flash'ов. –
Обратите внимание на мой последний комментарий. И спасибо за ваш вклад. – Vinozio