erb

Rendering js from a Rails controller with webpacker

孤人 提交于 2020-01-31 04:50:09
问题 Just replaced the js pipeline in my Rails app with webpacker . Most things work correctly, however controllers that render js no longer work as expected. def action format.js { render "javascript_partial" } end Normally, the above would execute a file in my view called javascript_partial.js.erb or action.js.erb if not specified in render . The problem seems to be that these files have no connection to the webpacker pipeline and thus cannot access global libraries like jquery or explicitly

Rails - Mix erb tags with markdown

♀尐吖头ヾ 提交于 2020-01-25 11:00:26
问题 I want the users on my blogsite to be able to type in markdown text in a textarea to make a blogpost. This markdown text would then be converted with a tool like Redcarpet or kramdown. Now I also want the user to be able to call a partial view that lays out some pictures. So in other words, I want the user to be able to type in the following code anywhere in between his markdown text (and it being interpreted as erb code) <%= render partial: "slider", locals: {imgs: ["image1.jpg", "image2.jpg

For a rack app, how do I make passenger-standalone serve the output of .erb files rather of sending the .erb file itself?

霸气de小男生 提交于 2020-01-17 09:28:32
问题 I have a simple config.ru rack app where I only require and run rack-server-pages to provide dynamic pages in a quick and convenient way. This config.ru app is served by phusion passenger-standalone (which uses nginx internally). .erb files are processed and served correctly, except when I explicitely add the .erb extension to a URL (for a .erb file). In that case the server will send me the .erb file for download, rather than its output. Obviously I would like to avoid that. To make it

Dynamic Javascript in my .html.erb

强颜欢笑 提交于 2020-01-14 09:21:30
问题 I'm struggling with some Javascript in my first rails application. Partial: _care_point.html.erb <script> $(function() { $( ".draggable" ).draggable({grid: [50, 20]}); $( ".node_input").each (function() { $(this).hide(); }); $("#<%="node.#{care_point.id}" %>").live('dblclick', function(){ console.log('moo'); jQuery(this).hide(); jQuery('.node_input', jQuery(this).parent()).show(); }); }); </script> <div id=<%="care_point.#{care_point.id}" %> class='draggable node_chin'> <div id=<%="node.#

flash[:alert] not working, but flash[:notice] displays the message on redirect

北慕城南 提交于 2020-01-14 04:59:04
问题 I am using rails_admin gem and the configuration is as follows config.authorize_with do if current_user.nil? || current_user.role != 'admin' redirect_to main_app.root_path flash[:alert] = "Sorry you are not authorized!" end end When I use flash[:notice] , I can see the message on the root_path, but if I change it to flash[:alert] it does not display, any ideas why and what would be the solution? I want to use :alert only, since changing the notice color will result it displaying red font for

Opening .html.erb files in browser

早过忘川 提交于 2020-01-07 04:10:54
问题 Is there a way to open .html.erb files by themselves in the browser. The Rails app I am trying to have a look at is in rails 2.3 and will not run locally on the rails server nor will it run when I give the command script/server. I would just like to open the individual views in the browser by themselves...is this possible? 回答1: You can open them in the browser, but the <% %> and <%= %> tags will get shown as-is instead of executing the Ruby code. These are template files that need to get

Embedded ruby “erb” tags [duplicate]

五迷三道 提交于 2020-01-03 15:58:52
问题 This question already has answers here : What is the difference between <%, <%=, <%# and -%> in ERB in Rails? (7 answers) Closed 5 years ago . I have been going through a crash course of Ruby and Ruby on Rails and i can't figure this out: In embedded ruby html files, there are several tags. <% %> for execution <%= %> for output, but what function do these tags serve: <%= -%>, what's with the "-" sign at the end ? Thanks. 回答1: This link contains a good overview of erb markup. From the site:

Embedded ruby “erb” tags [duplicate]

核能气质少年 提交于 2020-01-03 15:58:22
问题 This question already has answers here : What is the difference between <%, <%=, <%# and -%> in ERB in Rails? (7 answers) Closed 5 years ago . I have been going through a crash course of Ruby and Ruby on Rails and i can't figure this out: In embedded ruby html files, there are several tags. <% %> for execution <%= %> for output, but what function do these tags serve: <%= -%>, what's with the "-" sign at the end ? Thanks. 回答1: This link contains a good overview of erb markup. From the site:

Rails 3.2 - haml vs. erb. Is haml faster? (february 2012)

▼魔方 西西 提交于 2020-01-02 00:52:14
问题 I am working on a project and I am still thinking about using HAML (beautiful code, less size of view files) instead of classic ERB template. My worries why I didn't do it yet are the speed of generating views - I read an articles/benchmarks and there was almost always HAML slower than ERB - but the truth is, that the articles are 2-3 years old. So my question is, how looks the comparison these two template systems now, in the start of 2012? 回答1: Here are some benchmarks from someone in Nov

React JSX integration with erb and Ruby block syntax

我与影子孤独终老i 提交于 2020-01-01 18:02:13
问题 In my app/assets/javascripts/components/navbar.js.jsx.erb I can write something like this in the render function of my component (I'm using the gem react-rails): class Navbar extends React.Component { render() { return( <div className="navbar-header"> <ul> <li> <%= link_to root_path, className: 'navbar-brand' do %> <span className='glyphicon glyphicon-home'></span>   <%= I18n.t('menu.now') %> <% end %> </li> <li><%= link_to I18n.t('menu.archive'), archive_path%></li> </ul> </div> ); } } All