ruby-on-rails-4

<%= with a block in rails 4

丶灬走出姿态 提交于 2020-07-03 09:39:39
问题 I'm trying to use a block in a helper, but that's giving me this error: SyntaxError - syntax error, unexpected ')' ...rbout.concat(( green_title do ).to_s); _erbout.concat "\n ... ... ^ (erb):4254: syntax error, unexpected end-of-input, expecting ')' ; _erbout.force_encoding(__ENCODING__) ^: (erb):1649:in `' here's how I'm calling it: <%= green_title do %> text <% end %> and here's my helper: def green_title(&block) capture do concat content_tag(:h3) do yeld end end end 回答1: Your block is

<%= with a block in rails 4

▼魔方 西西 提交于 2020-07-03 09:39:05
问题 I'm trying to use a block in a helper, but that's giving me this error: SyntaxError - syntax error, unexpected ')' ...rbout.concat(( green_title do ).to_s); _erbout.concat "\n ... ... ^ (erb):4254: syntax error, unexpected end-of-input, expecting ')' ; _erbout.force_encoding(__ENCODING__) ^: (erb):1649:in `' here's how I'm calling it: <%= green_title do %> text <% end %> and here's my helper: def green_title(&block) capture do concat content_tag(:h3) do yeld end end end 回答1: Your block is

Capistrano deploy:assets:restore_manifest Rails assets manifest file (or backup file) not found

和自甴很熟 提交于 2020-06-27 07:48:30
问题 TLDR; I have been deploying with Capistrano for over a year and able to rollback and now all of a sudden I cannot rollback saying it cannot find the rake asset file Problem Capistrano Rollback is failing complaining that it cannot find the rake asset manifest which I validated is not there. What creates this and why would it just stop being created? I have been pulling my hair out for days over this and am at a point to figure out how to hack out that portion of the rollback and manually

rails 4, change default form builder globally

谁说我不能喝 提交于 2020-06-27 07:47:08
问题 I have sub-classed the default form builder to add some additional methods. Sample code is below. module ApplicationHelper class AppFormBuilder < ActionView::Helpers::FormBuilder def coordinates_field(method, options = {}) options[:readonly] = 'true' .... @template.text_field(@object_name, method, objectify_options(options)) end end end This works well, but to use it I have to change the view code for every form that uses the coordinates_field method, i.e., <%= form_for @object, :builder =>

How to get all the associated models from ActiveRecord object?

折月煮酒 提交于 2020-06-25 04:51:48
问题 For example I have class Order < ActiveRecord::Base has_many :shippings has_one :contact_information belongs_to :shop end How to get an array of associated objects from Order. For example Order.associations # [:shipping, :contact_information, :shop] 回答1: Order.reflect_on_all_associations.map(&:class_name) You can pass a type of relation as a parameter: Order.reflect_on_all_associations(:has_one) Read about ActiveRecord::Reflection::ClassMethods EDIT Just realised, you've asked about object's

Why does current_user session become nil when updating a user?

瘦欲@ 提交于 2020-06-25 04:00:10
问题 I'm using Devise and CanCan for user authentication and administrating roles restricting access to parts of my Rails 4 app for certain users. I've run into some problems with updating a user. The update works fine and the user object in the db get updated as it should, but my user session is lost on the following redirect_to my user show action. current_user becomes nil which means that CanCan restricts the access to the user show action. Why does current_user become nil after update, when

'Yarn install' cause 'trouble with network connection'

扶醉桌前 提交于 2020-06-14 04:11:01
问题 yarn install v0.21.3 [1/4] Resolving packages... warning There appears to be trouble with your network connection. Retrying... warning There appears to be trouble with your network connection. Retrying... warning There appears to be trouble with your network connection. Retrying... warning There appears to be trouble with your network connection. Retrying... warning There appears to be trouble with your network connection. Retrying... error An unexpected error occurred: "https://github.com

'Yarn install' cause 'trouble with network connection'

前提是你 提交于 2020-06-14 04:10:49
问题 yarn install v0.21.3 [1/4] Resolving packages... warning There appears to be trouble with your network connection. Retrying... warning There appears to be trouble with your network connection. Retrying... warning There appears to be trouble with your network connection. Retrying... warning There appears to be trouble with your network connection. Retrying... warning There appears to be trouble with your network connection. Retrying... error An unexpected error occurred: "https://github.com

'Yarn install' cause 'trouble with network connection'

点点圈 提交于 2020-06-14 04:10:47
问题 yarn install v0.21.3 [1/4] Resolving packages... warning There appears to be trouble with your network connection. Retrying... warning There appears to be trouble with your network connection. Retrying... warning There appears to be trouble with your network connection. Retrying... warning There appears to be trouble with your network connection. Retrying... warning There appears to be trouble with your network connection. Retrying... error An unexpected error occurred: "https://github.com

Check boxes search with Ransack gem

情到浓时终转凉″ 提交于 2020-06-09 11:39:51
问题 I need to filter data in a table. To do this, I found meta_search gem. I installed meta_search and I get this error: uninitialized constantActiveRecord::Associations::ClassMethods::JoinDependency This is deprecated for Rails 4 (framework that I'm using). So, I installed ransack (rails 4 branch) (gem based on meta_search) and works beautifully. The problem is that I need to use the meta_search's collection_checks method to handle check boxes and this method does not exist in ransack. So, the