content-for

Use content_for with src attribute of a script tag?

♀尐吖头ヾ 提交于 2021-01-29 08:03:44
问题 I figured out how to use content_for for some elements, for example <title> : <% content_for :title, "Hi, I'm #{@user.username}" %> But I can't seem to get it working when I need to inject a <script> tag with src attribute. I.e. this code: <script src="https://js.stripe.com/v3/"></script> How can I use content_for to place a script tag (with src attribute) in the head of a page? 回答1: Answer from another forum Add this to your head <%= yield :whatever_name_you_want %> And add this to your

how to use content_for so that the content shows up in the layout

孤者浪人 提交于 2019-12-22 04:42:39
问题 Am testing the content_for in my rails 3.2 app and following the rails guides but they are specific to the actual files and I cannot seem to get the yield to work: application.html.erb file: <!DOCTYPE html> <html> <head> ... </head> <body> <%= yield :navigation %> #shouldn't this load the content_for block named :navigation specified in the _main_nav.html.erb partial? <%= yield %> #this load the index page content </body> </html> I created a layout file _main_nav.html.erb (i know I can render

Using multiple yields to insert content

岁酱吖の 提交于 2019-12-21 17:28:05
问题 I am trying to insert content on my page with yield but every time action removes whole content from the page. I have one main yield which is working fine: <body> <%= render 'layouts/header' %> <div class="container"> <%= yield %> <%= render 'layouts/footer' %> </div> </body> But inside that new content which is displayed on one page I have another yield : <div class="container"> <%= render 'admins/menu' %> <%= yield :admin %> </div> When user clicks on the menu which is rendered, new content

how to render partial on everything except a certain action

爷,独闯天下 提交于 2019-12-17 21:50:57
问题 I have a _header.html.erb partial which is where I put my navbar on my launch page I don't want to display the navbar. this is the body of application.html.erb <body> <%= render 'layouts/header' %> <div id="container"> <%= yield %> </div> </body> How do I render it on every action except specific actions on specific controllers? 回答1: Replace your render with this: <%= render 'layouts/header' unless @disable_nav %> Then you can simply set disable_nav to true in any controller action you like:

Ruby on Rails's content_for will do an automatic HTML escape?

旧时模样 提交于 2019-12-12 12:10:09
问题 Using Rails 3.0.6, I found that in the view, if I do a content_for :food_name, "Macaroni & Cheese" Then when I get it back using content_for(:food_name) , then the & will be made into & already. It doesn't matter if I do a content_for(:food_name).html_safe , the & is still made into & already. But if done the following way, then it is not escaped: content_for :food_name, "Macaroni & Cheese".html_safe In this case, the & will not change to & automatically. Now, because there are places where I

content_for works in development but not production?

浪尽此生 提交于 2019-12-10 11:49:55
问题 I have a controller using caches_action controllers/bar_controller.rb: caches_action :bar, :layout => false and in the view of this action, I'ill setting html title in layout. views/foo/bar.html.erb: <%= content_for :mytitle do "testing" end %> this is my layout file: views/layouts/application.html.erb: <title><%= yield :mytitle %></title> However, this only work in development. In production, it does not work. Any idea is appreciated. thanks. similar question: Is there a workaround for

Multiple content_for on the same page

前提是你 提交于 2019-12-05 22:13:10
问题 I have large block of HTML in my application that I would like to move into a shared template and then use content_for with yields to insert the necessary content. However, if I use it more than once in the same layout file the content_for just appends to the previous making that idea not work so well. Is there a solution to this? <div class="block side"> <div class="block_head"> <div class="bheadl"></div> <div class="bheadr"></div> <h2><%= yield :block_head %></h2> </div> <div class="block

Using multiple yields to insert content

对着背影说爱祢 提交于 2019-12-04 10:55:44
I am trying to insert content on my page with yield but every time action removes whole content from the page. I have one main yield which is working fine: <body> <%= render 'layouts/header' %> <div class="container"> <%= yield %> <%= render 'layouts/footer' %> </div> </body> But inside that new content which is displayed on one page I have another yield : <div class="container"> <%= render 'admins/menu' %> <%= yield :admin %> </div> When user clicks on the menu which is rendered, new content should be displayed below that menu. admins/_menu.html.erb <div class="navbar"> <div class="navbar

Ruby on Rails: provide vs content_for

女生的网名这么多〃 提交于 2019-12-03 05:38:34
问题 I came across the view helper function "provide" today. By looking into its manual I am still confused on how it is different from "content_for". provide(name, content = nil, &block) The same as content_for but when used with streaming flushes straight back to the layout. In other words, if you want to concatenate several times to the same buffer when rendering a given template, you should use content_for, if not, use provide to tell the layout to stop looking for more contents. Question 1:

Including inline javascript using content_for in rails

帅比萌擦擦* 提交于 2019-11-29 20:44:42
I am using content_for and yeild to inject javascript files into the bottom of my layout but am wondering what the best practice is for including inline javascript. Specifically I'm wondering where the put the script type declaration: <% content_for :javascript do %> <script type="text/javascript"> ... </script> <% end %> or <% content_for :javascript do %> ... <% end %> <script type="text/javascript"> <%= yield :javascript %> </script> <% end %> I am using the first option now and wondering if it is bad to include multiple ... declarations within one view. Sometimes I have partials that lead