actionviewhelper

Using helpers in rails 3 to output html

这一生的挚爱 提交于 2019-11-28 17:14:45
I'm trying my best to build a helper that outputs a <'ul> consisting of all the members of a collection. For each member of the collection I want to print out a <'li> that has a title, and a div of links to CRUD the member. This is pretty similar to what Rails outputs for scaffolding for the index view. Here is the helper I've got: def display_all(collection_sym) collection = collection_sym.to_s.capitalize.singularize.constantize.all name = collection_sym.to_s.downcase html = '' html << "<ul class=\"#{name}-list\">" for member in collection do html << content_tag(:li, :id => member.title.gsub(

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

How to include ActionView helpers in the assets pipeline?

江枫思渺然 提交于 2019-11-27 21:33:02
How to include Rails view helpers to be accesible by assets pipeline execution context? An example use case would be to generate the markup for a form, using form_tag helper method, and make it available to a Javascript template (like handlebars, jst, etc.). I use handlebar_assets gem, but this should apply to any erb or haml template too. Create a inititializer and include the helpers in the context of the assets like this: Rails.application.assets.context_class.class_eval do include ActionView::Helpers include MyAppHelper include Rails.application.routes.url_helpers end Taken from this

Using helpers in rails 3 to output html

让人想犯罪 __ 提交于 2019-11-27 10:31:32
问题 I'm trying my best to build a helper that outputs a <'ul> consisting of all the members of a collection. For each member of the collection I want to print out a <'li> that has a title, and a div of links to CRUD the member. This is pretty similar to what Rails outputs for scaffolding for the index view. Here is the helper I've got: def display_all(collection_sym) collection = collection_sym.to_s.capitalize.singularize.constantize.all name = collection_sym.to_s.downcase html = '' html << "<ul

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

How to include ActionView helpers in the assets pipeline?

你。 提交于 2019-11-26 20:45:44
问题 How to include Rails view helpers to be accesible by assets pipeline execution context? An example use case would be to generate the markup for a form, using form_tag helper method, and make it available to a Javascript template (like handlebars, jst, etc.). I use handlebar_assets gem, but this should apply to any erb or haml template too. 回答1: Create a inititializer and include the helpers in the context of the assets like this: Rails.application.assets.context_class.class_eval do include