actionview

Rails distance_of_time_in_words returns “en, about_x_hours”

拟墨画扇 提交于 2019-12-03 00:28:06
I'm having a weird problem, hoping someone knows what the issue is... Using distance_of_time_in_words (and consequently time_ago_in_words) is not returning the actual time distance. Instead it is returning things like "en, about_x_hours" or "en, x_minutes". The pattern is correct, as in: time_ago_in_words(50.minutes.ago) => "en, about_x_hours" time_ago_in_words(3.minutes.ago) => "en, x_minutes" But why on earth is it displaying "x" instead of the actual number, "_" instead of spaces, and "en, " at the beginning of all of that?! That gives back a string to translate via the I18n-gem.... Try

What should I pass for root when inflating a layout to use for a MenuItem's ActionView?

青春壹個敷衍的年華 提交于 2019-12-02 20:06:45
I have an ImageView that I attach to a MenuItem as its ActionView (the item appears in the ActionBar ). The layout for this view comes from XML. I'm inflating it like so: ImageView actionView = (ImageView) layoutInflater.inflate( R.layout.action_view_layout, null); This appears to work fine. However; passing null for root in the call to inflate() makes Lint yell at me: Avoid passing null as the view root (need to resolve layout parameters on the inflated layout's root element) I can seemingly manage without a root in my specific case, but I'd rather have the code be as correct as possible. The

How to render images in rails3 select

≯℡__Kan透↙ 提交于 2019-12-01 20:58:56
I want to render dropdown list in form with images as options. How to achieve this in rails3? gabrielhilal I like the msdropdown . You can add the path for the image in the title tag: <select> <option value="1" title="#path for the image">first</option> <option value="2" title="#path for the image">second</option> ... </select> In Rails, you can add the title doing something like: <%= f.select(:yourcolumn, Model.all.map{|p| [p.name, p.id, :title => p.image_url(:thumb)]} I have faced a similar problem some time ago: generate HTML <select> with title inside each <option> to apply the msDropDown

render default template when requested template is missing in Rails

梦想与她 提交于 2019-12-01 19:50:18
问题 For a plugin I want to hack the following feature into Rails: When a (partial) template does not exist (regardless of the format) I want to render a default template. So say I call an action 'users/index' if users/index.html.erb does not (or other format) exist, 'default/index.html.erb' should be rendered. Similarly, If I call an action 'locations/edit' and 'locations/edit.html.erb' does not exist, 'default/edit.html.erb' should be rendered For partials, If I call an action 'locations/index'

Trying to extend ActionView::Helpers::FormBuilder

大城市里の小女人 提交于 2019-12-01 09:10:29
I am trying to DRY up some code by moving some logic into the FormBuilder. After reading the documentation about how to select and alternative form builder the logical solution for me seemed to be something like this. In the view <% form_for @event, :builder => TestFormBuilder do |f| %> <%= f.test %> <%= f.submit 'Update' %> <% end %> and then in app/helpers/application_helper.rb module ApplicationHelper class TestFormBuilder < ActionView::Helpers::FormBuilder def test puts 'apa' end end end This, however, gives me an error at the "form_for" uninitialized constant ActionView::Base:

How does the yield magic work in ActionView?

一笑奈何 提交于 2019-12-01 08:45:07
I was looking at how content_for works and observed the block.call in the capture_erb_with_buffer method. It apparently magically writes to the buffer variable which is then pruned. However, this I believe is deprecated and you can just call <%=yield :tag%> now. How does this work? If I call yield from an ERB template where does that yield to? A simple code sample to illustrate the point would be greatly appreciated. This little tiny method called execute in ActionView::Base explains it all. http://google.com/codesearch/p?hl=en#m8Vht-lU3vE/vendor/rails/actionpack/lib/action_view/base.rb&q

Trying to extend ActionView::Helpers::FormBuilder

泄露秘密 提交于 2019-12-01 07:47:17
问题 I am trying to DRY up some code by moving some logic into the FormBuilder. After reading the documentation about how to select and alternative form builder the logical solution for me seemed to be something like this. In the view <% form_for @event, :builder => TestFormBuilder do |f| %> <%= f.test %> <%= f.submit 'Update' %> <% end %> and then in app/helpers/application_helper.rb module ApplicationHelper class TestFormBuilder < ActionView::Helpers::FormBuilder def test puts 'apa' end end end

How to prevent Rails from Action View logging in production

拟墨画扇 提交于 2019-12-01 07:31:08
In rails 3.2.0,is it possible to turn off rails logging for rendering of views in ActionView:: LogSubscriber in production environment. Currently only way i found to supress is to monkey patch it and increase the log level to debug in the below way. Is there a better way to do this or any configuration? module ActionView class LogSubscriber def render_template(event) message = "Rendered #{from_rails_root(event.payload[:identifier])}" message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout] message << (" (%.1fms)" % event.duration) debug(message) end alias

How to prevent Rails from Action View logging in production

流过昼夜 提交于 2019-12-01 05:08:02
问题 In rails 3.2.0,is it possible to turn off rails logging for rendering of views in ActionView:: LogSubscriber in production environment. Currently only way i found to supress is to monkey patch it and increase the log level to debug in the below way. Is there a better way to do this or any configuration? module ActionView class LogSubscriber def render_template(event) message = "Rendered #{from_rails_root(event.payload[:identifier])}" message << " within #{from_rails_root(event.payload[:layout

Changing view on Menu Item in Action Bar

混江龙づ霸主 提交于 2019-12-01 04:46:29
I'm attempting to implement a refresh button in my app to allow a user to manually re-sync to a web server. The code works, but I'm having trouble figuring out the action views (at least, I think that's what I'm supposed to be using). My menu item is here: <item android:id="@+id/main_menu_refresh" android:enabled="true" android:icon="@drawable/refresh" android:orderInCategory="1" android:showAsAction="ifRoom" android:title="@string/refresh" android:actionViewClass="android.widget.ProgressBar"> </item> The problem is, it always shows the ProgressBar. I wondered if it worked like the search