actionview

ActionView::Template::Error (960.css isn't precompiled)

烈酒焚心 提交于 2019-11-29 01:11:18
I have an iframe which renders a partial and is not part of the main application layout or asset pipeline. I'd like to include some style sheets, however I am getting this error: ActionView::Template::Error (960sm.css isn't precompiled): Rails 3.1 Heroku Style sheets that are not included in a manifest (directly by name or indirectly via require_tree) are not precompiled, so will not accessible in production. You need to add the sheet to the list of items to precompile in the environment application.rb. config.assets.precompile += ['960sm.css'] And then access it in the view: stylesheet_link

How do I expire a view cached fragment from console?

柔情痞子 提交于 2019-11-29 00:23:15
问题 Something like Rails.cache.delete('site_search_form') doesn't seem to work. Is this possible? Thanks. 回答1: Cache fragment entries are created with a slightly different key than what you access with Rails.cache. Use expire_fragment instead (you can send it to a controller): http://api.rubyonrails.org/classes/ActionController/Caching/Fragments.html#M000438 回答2: ActionController::Base.new.expire_fragment(key) 回答3: Rails.cache.delete "views/site_search_form" 回答4: In Rails 5 I took the following

Rails - ActionView::Base.field_error_proc moving up the DOM tree?

帅比萌擦擦* 提交于 2019-11-28 18:28:58
Is there anyway to go up the DOM tree from the html_tag element passed in? ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| # implementation end Is there anyway I can implement this method to move up the DOM tree and place a class on the parent div? For example: <div class="email"> <label for="user_email">Email Address</label> <input id="user_email" name="user[email]" size="30" type="text" value=""> </div> I would like to place a class on the div.email rather than place something directly on the input/label. Can this be done with the field_error_proc method or is there a

Rails: Should partials be aware of instance variables?

妖精的绣舞 提交于 2019-11-28 03:15:02
Ryan Bates' nifty_scaffolding, for example, does this edit.html.erb <%= render :partial => 'form' %> new.html.erb <%= render :partial => 'form' %> _form.html.erb <%= form_for @some_object_defined_in_action %> That hidden state makes me feel uncomfortable, so I usually like to do this edit.html.erb <%= render :partial => 'form', :locals => { :object => @my_object } %> _form.html.erb <%= form_for object %> So which is better: a) having partials access instance variables or b) passing a partial all the variables it needs? I've been opting for b) as of late, but I did run into a little pickle:

How can I add a view path to Rails's partial rendering lookup?

时光毁灭记忆、已成空白 提交于 2019-11-27 21:59:57
I'd like to have the following directory structure: views/ app1/ users/_user.html.erb users/index.html.erb app2/ users/index.html.erb shared/ users/_user.html.erb users/index.html.erb In my view, I'd call # app1/users/index.html <%= render :partial => "user" %> # => /app1/users/_user.html.erb # app2/users/index.html <%= render :partial => "user" %> # => /shared/users/_user.html.erb So basically, how do I tell Rails to check in the /app2/users dir then the shared dir before it raises it's missing template error? Update I got around this (as suggested by Senthil, using File.exist? Here's my

Rails - ActionView::Base.field_error_proc moving up the DOM tree?

我是研究僧i 提交于 2019-11-27 20:20:39
问题 Is there anyway to go up the DOM tree from the html_tag element passed in? ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| # implementation end Is there anyway I can implement this method to move up the DOM tree and place a class on the parent div? For example: <div class="email"> <label for="user_email">Email Address</label> <input id="user_email" name="user[email]" size="30" type="text" value=""> </div> I would like to place a class on the div.email rather than place

ActionView::Template::Error (960.css isn't precompiled)

≯℡__Kan透↙ 提交于 2019-11-27 15:42:14
问题 I have an iframe which renders a partial and is not part of the main application layout or asset pipeline. I'd like to include some style sheets, however I am getting this error: ActionView::Template::Error (960sm.css isn't precompiled): Rails 3.1 Heroku 回答1: Style sheets that are not included in a manifest (directly by name or indirectly via require_tree) are not precompiled, so will not accessible in production. You need to add the sheet to the list of items to precompile in the environment

Dynamic error pages in Rails 3

巧了我就是萌 提交于 2019-11-27 10:52:14
In Rails 2.3.x, you can override render_optional_error_file like so: # ApplicationController.rb protected def render_optional_error_file(status_code) render :template => "errors/500", :status => 500, :layout => 'application' end However, Rails 3 no longer has render_optional_error_file . Instead, you need to override rescue_action_in_public , which you can do like so: # config/initializers/error_page.rb module ActionDispatch class ShowExceptions protected def rescue_action_in_public(exception) status = status_code(exception).to_s template = ActionView::Base.new(["#{Rails.root}/app/views"]) if

How do I extract Rails view helpers into a gem?

删除回忆录丶 提交于 2019-11-27 10:31:41
I have a set of rails view helpers that I use regularly, and would like to package them up into a gem, such that I could just put a line in my Gemfile, and have the helpers accessible from my views. I have created gems before using Bundler, and Jeweler, however, I'm not all all clear on how to organize the Rails view helpers in a gem, and include them into rails. I would appreciate any pointers, or links to up-to-date tutorials on how to do this for Rails 3 Thanks Just to clarify: The question isn't on "how to create a gem". Its "how to package view helpers in a gem, so I can use them in Rails

How can I add a view path to Rails's partial rendering lookup?

会有一股神秘感。 提交于 2019-11-27 04:32:57
问题 I'd like to have the following directory structure: views/ app1/ users/_user.html.erb users/index.html.erb app2/ users/index.html.erb shared/ users/_user.html.erb users/index.html.erb In my view, I'd call # app1/users/index.html <%= render :partial => "user" %> # => /app1/users/_user.html.erb # app2/users/index.html <%= render :partial => "user" %> # => /shared/users/_user.html.erb So basically, how do I tell Rails to check in the /app2/users dir then the shared dir before it raises it's