Rails

Rails polymorphic has_many :through

匿名 (未验证) 提交于 2019-12-03 01:27:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm pulling some data from an external API and would like to cache the results locally. I have a class SearchTerm , which I would like to be associated with a few different ActiveRecord types through the table searchable_items . I'm pretty sure I have the tables set up correctly, but something in my associations must be wrong. class Foo :searchable, :through => :searchable_items end class Bar :searchable, :through => :searchable_items end class SearchTerm :searchable_items end class SearchableItem true end I would expect to be able to do

On Migration: undefined method `to_sym' for nil:NilClass

匿名 (未验证) 提交于 2019-12-03 01:27:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm running Rails 3.0.3 and I accidentally made a typo in my migration: I created a migration that creates a new column with a type of boolen (it should have been boolean ). I ran the migration and Rails didn't warn me that this was an invalid type of column, which I could have sworn it did in previous versions? Now whenever I try to add, remove, or modify anything in a migration I get the following error: undefined method `to_sym' for nil:NilClass I can't even rollback or drop. I have an earlier version of the database and file

Dynamic routes with Rails 3

匿名 (未验证) 提交于 2019-12-03 01:26:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a task to develop a rails application following the model for routing. I need to have PageController and Page model. Page urls must be like /contacts, /shipping, /some_page . Also i need have CatalogController and Category model. Categories urls must be like /laptops, /smartphones/android . And it will be ProductsController and Product model, urls of products must be line /laptops/toshiba_sattelite_l605 , /smartphones/android/htc_magic I understand that this problem can be solved by using URLs like /page/shipping /catalog/smartphones

ExecJS::ProgramError: Unexpected character '#'

匿名 (未验证) 提交于 2019-12-03 01:26:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to deploy to Heroku and I am met with this error. I've done some research and tried uninstalling and reinstalling some gems after looking at relevant posts but I'm not really sure what's wrong here as I am not familiar with what the actual problem is. Please help! What should I do? So far I'm thinking it has something to do with the jquery. ExecJS::ProgramError: Unexpected character '#' (line: 13912, col: 0, pos: 394110) remote: Error remote: at new JS_Parse_Error (/tmp/execjs20150204-1143-zrnj29js:2359:10623) remote: at js_error

Rails Multiple Check Box with drop down list

匿名 (未验证) 提交于 2019-12-03 01:26:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have created an associated models to create a check box list, where user can select languages that he/she speaks. I have tried to use both Chosen and Select2 but could not make it work. The problem might be because I use check_box_tag Here is my code; <%= hidden_field_tag "user[language_ids][]" , nil %> <% Language . all . each do | language | %> <%= check_box_tag "user[language_ids][]" , language . id , @user . language_ids . include ?( language . id ), id : dom_id ( language ) %> <%= label_tag dom_id ( language ), language .

Rails 4/ ajax - NoMethodError - undefined method `id&#039; for nil:NilClass - Passing variable to js modal

匿名 (未验证) 提交于 2019-12-03 01:26:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a pretty simple Ruby On Rails app with bootstrap 3 for the front end: I have Deals, and each Deal has_many Opportunities. On each Deal page (url of deal page is for example myapp.com/id=1), I want to have a textual link that says "view deal's opportunities" and when clicked, it trigger when clicked the appearance of content inside a Bootstrap modal. I'm getting all mixed up because on this Deal Page, I use Deal's controller action called "showcase". BUT to generate the modal via ajax,as you see below, I use another action called "show

How to upgrade from rails 4.2.6 to rails 5.0

匿名 (未验证) 提交于 2019-12-03 01:25:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Is there a console way i can upgrade my rails to the new 5.0 version? Or do i have to manually go replace each file that's needed to upgrade? The Interne seems vague in giving me a solution to this problem. 回答1: I just went through this a few days ago, and this was my (successful) process: First, make sure your app runs on Ruby 2.2+ before upgrading. Then update Rails to the latest 4.x version (4.2.7 right now), and run your test suite (or fully exercise your app) watching the log for Deprecation warnings. Fix those deprecations if

Validation in Rails without a model

匿名 (未验证) 提交于 2019-12-03 01:25:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a form that allows the user to send a message to an email, and I want to add validation to it. I do not have a model for this, only a controller. How should I do this in Rails? I was considering doing the validation in the controller, and displaying the errors to the user using the flash object. Is there a better way of doing this? 回答1: The best approach would be to wrap up your pseudo-model in a class, and add the validations there. The Rails way states you shouldn't put model behavior on the controllers, the only validations there

rails error method_missing&#039;: undefined method `this&#039; for Gem::Specification

匿名 (未验证) 提交于 2019-12-03 01:25:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I follow this tutorial: https://guides.spreecommerce.com/developer/getting_started_tutorial.html#installing-image-magick When I write jonstark@jonstark-pc:~/rails_projects/optima1$ spree install --auto-accept I got this: /home/jonstark/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/specification.rb:2158:in `method_missing': undefined method `this' for # (NoMethodError) from /home/jonstark/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/specification.rb:1057:in `find_active_stub_by_path' from /home/jonstark/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3

Rails 3 Mysql Problems

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Trying to start a new Rails 3 beta 4 app with mysql.... Running OS X Snow Leopard. WIth previous versions of Rails I have no problem with MySQL. But now when I start the Rails 3 app I get the following error when I click "About Your Application Environment" on the Rails index.html startup screen: undefined method `init' for Mysql:Class 回答1: Change your Gemfile to use 'mysql2', it's a more modern driver and has nicer features as other people have mentioned. New Rails applications use the mysql2 gem by default. 回答2: I ran into the same issue