partials

Render form partial in a different controller (not nested)

依然范特西╮ 提交于 2019-11-29 02:30:31
问题 I have two models generated with generate scaffolding, one is a LogBook the other is LogEntry. I want to render the form partial for LogEntry on the LogBook show page. When I call render on the partial I get this error: undefined method `model_name' for NilClass:Class I assume it is because the default _form uses an instance variable which isn't present when called from a separate controller. So I tried converting the LogEntry _form.html.erb to use local variables and passed them in via the

Rails passing form_for object to partial

隐身守侯 提交于 2019-11-29 02:10:30
问题 I would like to pass the form_for object to a partial: <%= form_for @price do |f| %> ... <%= render :partial => "price_page", :object => @price, :as => :f %> ... <% end %> When I call: f.radio_button Brings the error: undefined method `radio_button' for #<Price:0x3cb1ed0> How can I use f as I usually would in this partial? 回答1: Try passing form object as local <%= render :partial => "price_page", :locals=>{:f=>f} %> 回答2: You can pass form builder object as a local variable like below, <%=

How to use HTML in Express framework with nunjucks- no jade

◇◆丶佛笑我妖孽 提交于 2019-11-28 17:04:05
I have been using sendFile method to render Html in Express project. I would like to use partials with my project. And, not switch to jade. Is there a way to use traditional HTML with partials in Express 3.x. I have tried ejs, but dont understand it completely. A more 'HTML-like' templating engine would be nunjucks (whose syntax is similar to Jinja2, which you have experience with). Here's a simple setup. This assumes both Express and Nunjucks are installed, if not: npm install express npm install nunjucks – app.js var nunjucks = require('nunjucks'); var express = require('express'); var app =

Angularjs: Multiples partials in single html?

删除回忆录丶 提交于 2019-11-28 15:59:22
问题 Is possible retrieve multiples html partials in one single html? I've the next situation: Template: {header} {main} {footer} /index: header:"Welcome" main:"welcome text" footer:"" /help: header:"Help title" main:"faq tips" footer"Back to home" using ng-include I've to retreive 6 html from server. If I will retrive multiples partials in one html then I will retrieve 2 html from server only, one for /index and one for /help. This situation is a small example the real situation. The tag script

How can I automatically render partials using markdown in Rails 3?

血红的双手。 提交于 2019-11-28 15:32:09
I want to have some of my partials as markdown snippets. What is the easiest way to render them using the standard rails erb templating? Ideally, I'd like to do something like this: If I have a partial in app/views/_my_partial.md.erb : My awesome view =============== Look, I can **use** <%= language %>! which I reference from a view like so: <%= render "my_partial", :language => "Markdown!" %> I want to get output that looks like this: <h1>My awesome view</h1> <p>Look, I can <strong>use</strong> Markdown!</p> Turns out, the Right Way (tm) to do this is using ActionView::Template.register

Rails No route matches {:controller=>“devise/products”}

冷暖自知 提交于 2019-11-28 01:10:06
问题 I get the below error on my rails application when I try to login or register (I'm using the Devise GEM for logins). Routing Error No route matches {:controller=>"devise/products"} All the source code for the application can be found here: https://github.com/rossmc/topsnowboards I've tried changing the link_to in application.html.erb & product/index.html.erb from: <%= link_to 'sign in', new_user_session_path %> to: <%= link_to 'sign in', :controller => "/products", new_user_session_path %>.

When to use Helpers instead of Partials

↘锁芯ラ 提交于 2019-11-27 19:58:35
In a rails application, in which situation would you use a partial and when would you use a helper? I find both very similar, since they represent markup fragments. Is there a convention around this? which is the 'rails way' of using them? Thanks! I guess my rule of thumb is to use a helper to build a single "unit" of display -- like a span containing a link -- and to use a partial to build a more complex unit of display composed of more than one "unit" of display -- like a grid or a menu. A partial is a view fragment, a piece of a view that is useful in multiple places and is pulled out so as

optional local variables in rails partial templates: how do I get out of the (defined? foo) mess?

房东的猫 提交于 2019-11-27 16:37:46
I've been a bad kid and used the following syntax in my partial templates to set default values for local variables if a value wasn't explicitly defined in the :locals hash when rendering the partial -- <% foo = default_value unless (defined? foo) %> This seemed to work fine until recently, when (for no reason I could discern) non-passed variables started behaving as if they had been defined to nil (rather than undefined). As has been pointed by various helpful people on SO, http://api.rubyonrails.org/classes/ActionView/Base.html says not to use defined? foo and instead to use local_assigns

Rails 4 rendering a partial with ajax, jquery, :remote => true, and respond_to

风格不统一 提交于 2019-11-27 11:15:06
It seems like rendering a page dynamically with AJAX in response to a submitted form is common. None of the other similar questions are focused around how to do this in a general way. The best blog post I could find on the subject was here: http://www.gotealeaf.com/blog/the-detailed-guide-on-how-ajax-works-with-ruby-on-rails The question: How do I code my rails application so that I can trigger a partial view to load via AJAX when I submit a form or click a link? Several things must be present for this to work, including the :remote => true flag on the triggering element, the respond_to :js

How to use HTML in Express framework with nunjucks- no jade

折月煮酒 提交于 2019-11-27 10:08:49
问题 I have been using sendFile method to render Html in Express project. I would like to use partials with my project. And, not switch to jade. Is there a way to use traditional HTML with partials in Express 3.x. I have tried ejs, but dont understand it completely. 回答1: A more 'HTML-like' templating engine would be nunjucks (whose syntax is similar to Jinja2, which you have experience with). Here's a simple setup. This assumes both Express and Nunjucks are installed, if not: npm install express