Ruby on rails RubyonRails-创建新记录后在show视图中显示引导模式
在我的show视图中,我有一个引导模式,我只想在创建新记录时“激活” 我的控制器:Ruby on rails RubyonRails-创建新记录后在show视图中显示引导模式,ruby-on-rails,ruby,twitter-bootstrap,Ruby On Rails,Ruby,Twitter Bootstrap,在我的show视图中,我有一个引导模式,我只想在创建新记录时“激活” 我的控制器: def create @request = current_user.requests.build(request_params) respond_to do |format| if @request.save format.html { redirect_to @request, notice: 'Request was successfully created.'
def create
@request = current_user.requests.build(request_params)
respond_to do |format|
if @request.save
format.html { redirect_to @request, notice: 'Request was successfully created.' }
format.json { render :show, status: :created, location: @request }
else
format.html { render :new }
format.json { render json: @request.errors, status: :unprocessable_entity }
end
end
end
我当前的节目视图:
#msgModal.modal.fade{"aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}
.modal-dialog{:role => "document"}
.modal-content
.modal-header
%button.close{"aria-label" => "Close", "data-dismiss" => "modal", :type => "button"}
%span{"aria-hidden" => "true"} ×
%h4#myModalLabel.modal-title.text-muted One last step before we are good to go :)
.modal-body
%h4 Share your post with your friends to start on good foot ;)
%img{:alt => "Sixpercent", :src => "http://localhost:8888/sixpercent.png", :style => "width: 420px;display: block;margin-left: auto;margin-right: auto;\n"}
%br
%button.btn.btn-success.font-bold.txt-shadow-dark{"data-target" => "#msgModal", "data-toggle" => "modal", :type => "button"}
#{icon('commenting-o')} Sharing div activater
如何以干净的方式管理它?您需要Rails的“flash”功能。闪存是在用户的会话cookie上设置的值。它持续一页的加载。有关本页5.2的更多详细信息: 例如,您可以根据闪光灯的存在修改视图以执行不同的操作。e、 g:
- if flash[:notice] == 'Request was successfully created.'
#msgModal.modal.fade{"aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}
.modal-dialog{:role => "document"}
.modal-content
.modal-header
%button.close{"aria-label" => "Close", "data-dismiss" => "modal", :type => "button"}
%span{"aria-hidden" => "true"} ×
%h4#myModalLabel.modal-title.text-muted One last step before we are good to go :)
.modal-body
%h4 Share your post with your friends to start on good foot ;)
%img{:alt => "Sixpercent", :src => "http://localhost:8888/sixpercent.png", :style => "width: 420px;display: block;margin-left: auto;margin-right: auto;\n"}
%br
希望有帮助!如果我错过了您要做的事情,我很抱歉:-)您需要Rails的“flash”功能。闪存是在用户的会话cookie上设置的值。它持续一页的加载。有关本页5.2的更多详细信息: 例如,您可以根据闪光灯的存在修改视图以执行不同的操作。e、 g:
- if flash[:notice] == 'Request was successfully created.'
#msgModal.modal.fade{"aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}
.modal-dialog{:role => "document"}
.modal-content
.modal-header
%button.close{"aria-label" => "Close", "data-dismiss" => "modal", :type => "button"}
%span{"aria-hidden" => "true"} ×
%h4#myModalLabel.modal-title.text-muted One last step before we are good to go :)
.modal-body
%h4 Share your post with your friends to start on good foot ;)
%img{:alt => "Sixpercent", :src => "http://localhost:8888/sixpercent.png", :style => "width: 420px;display: block;margin-left: auto;margin-right: auto;\n"}
%br
希望有帮助!如果我错过了你想做的事情的要点,我很抱歉:-)这对我很有效
如果在局部视图中有模态,则在您的视图中:
然后:
`<% if flash[:notice].present? %>
<script>
$(document).ready(function(){
$('#myModal').modal("show");
});
</script>
<% end %>`
`
$(文档).ready(函数(){
$('myModal').modal(“show”);
});
`
这对我很有效
如果在局部视图中有模态,则在您的视图中:
然后:
`<% if flash[:notice].present? %>
<script>
$(document).ready(function(){
$('#myModal').modal("show");
});
</script>
<% end %>`
`
$(文档).ready(函数(){
$('myModal').modal(“show”);
});
`