ruby-on-rails-4

Should you still pass only the object id when using ActiveJob?

谁都会走 提交于 2020-01-13 07:53:11
问题 What are the pros and cons of doing the following in ActiveJob: Option A: // Controller MyJob.perform_later(object.id) // my_job.rb def perform(object_id) object = Object.find(object_id) // do stuff end Option B: // Controller MyJob.perform_later(object) // my_job.rb def perform(object) // do stuff end 回答1: ActiveJob now uses the new Globalid library behind the scenes to serialize/deserialize an ActiveRecord instance, therefore you can now pass an ActiveRecord object. I personally prefer to

Creating multiple nested forms using simple_form and rails 4

我的梦境 提交于 2020-01-13 07:44:06
问题 I'm trying to create a simple app with the following models: categories --[has_many]--> questions --[has_many]--> answers I have the following code for creating categories + questions(categories/_form.haml.html): = simple_form_for(@category) do |f| = f.error_notification = f.input :title, label: "Category title: " = f.simple_fields_for :questions, @category.questions.build do |q| = q.input :content, label: "Question content: " = f.button :submit And I'm using all the same code for creating

Ruby on Rails error: “Undefined method `call' for ”result == false“:String” error in create method

雨燕双飞 提交于 2020-01-13 05:15:48
问题 When I try to create a listing in my app with an image this error is thrown: undefined method `call' for "result == false":String. The error occurred after I installed devise gem. But devise shouldn't have anything to do with creating a new listing? The other parts of the app works fine, and I can create new listings without images. Error message NoMethodError in ArtistsController#create undefined method `call' for "result == false":String The method it points to is a callback method in

Association between Category, Subcategory, and Lawyer

末鹿安然 提交于 2020-01-13 04:55:47
问题 I have a vast list of Lawyers, Categories, and Subcategories. Hint (so you could have a clue if my associations are okay) On Categories Table, I do not want to see a column on Categories Table referencing Subcategories. On Subcategories Table, I do not want to see a column on Subcategories Table referencing Categories. Not all Categories has Subcategories. i.e. some don't have subcategories as seen in the picture. I have 2 separate forms creating category and subcategory. I added category_id

Association between Category, Subcategory, and Lawyer

泄露秘密 提交于 2020-01-13 04:55:06
问题 I have a vast list of Lawyers, Categories, and Subcategories. Hint (so you could have a clue if my associations are okay) On Categories Table, I do not want to see a column on Categories Table referencing Subcategories. On Subcategories Table, I do not want to see a column on Subcategories Table referencing Categories. Not all Categories has Subcategories. i.e. some don't have subcategories as seen in the picture. I have 2 separate forms creating category and subcategory. I added category_id

Rails 4: favicon not showing

浪尽此生 提交于 2020-01-13 03:19:25
问题 My favicon just won't show, in Chrome or Firefox. This is how I am rendering it in the <head> section: <%= favicon_link_tag 'favicon.ico' %> It is located in public/images . This is the produced HTML: <link rel="shortcut icon" type="image/x-icon" href="/images/favicon.ico"> Opening the link in my browser shows the icon correctly. 回答1: The favicon is not handled by the asset pipeline when its in the public folder, and this can cause caching problems. See here: How to add favicon in rails 3.2

Pry-Remote with Pow on Rails 4

百般思念 提交于 2020-01-13 02:44:28
问题 I'm busy with (finally) upgrading to Rails 4 and I've run into a problem with Pry-remote. Problem: When added binding.remote_pry to my code it breaks the code but when I can't get into the debugger by typing pry-remote . This used to work when running Rails 3 and Ruby 1.9.3. Side note: When running Rails s instead of Pow and binding.pry instead binding.remote_pry , it falls into the debugger. What I'm running: Pow 0.5.0 ruby 2.1.5p273 Rails 4.2.0 OSX 10.9.5 Gemfile gem 'pry' gem 'pry-remote'

After submitting a remote form with Rails, how do I redirect the user to another page?

北慕城南 提交于 2020-01-12 09:23:50
问题 I’m using Rails 4.2.3. I want to submit a form in a modal dialog, so I have set up my form like so <%= form_for @my_object, :remote => true do |f| %> but if the user submits the form successfully, I would like to reload the page that invoked the modal dialog with a notice of “Saved Successfully.” I can’t figure out what I need to put in my “format.js” to make this happen. This is what I have in my controller so far … def create @my_object = MyObject.new(my_object_params) @current_user = User

After submitting a remote form with Rails, how do I redirect the user to another page?

这一生的挚爱 提交于 2020-01-12 09:23:43
问题 I’m using Rails 4.2.3. I want to submit a form in a modal dialog, so I have set up my form like so <%= form_for @my_object, :remote => true do |f| %> but if the user submits the form successfully, I would like to reload the page that invoked the modal dialog with a notice of “Saved Successfully.” I can’t figure out what I need to put in my “format.js” to make this happen. This is what I have in my controller so far … def create @my_object = MyObject.new(my_object_params) @current_user = User

After submitting a remote form with Rails, how do I redirect the user to another page?

我与影子孤独终老i 提交于 2020-01-12 09:21:45
问题 I’m using Rails 4.2.3. I want to submit a form in a modal dialog, so I have set up my form like so <%= form_for @my_object, :remote => true do |f| %> but if the user submits the form successfully, I would like to reload the page that invoked the modal dialog with a notice of “Saved Successfully.” I can’t figure out what I need to put in my “format.js” to make this happen. This is what I have in my controller so far … def create @my_object = MyObject.new(my_object_params) @current_user = User