Rails

Rails set default DateTime to now

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In my app I have teams and each team has a game time every week. I want the game times to be set to 'now' as a default. My table is set up like so create_table "teams", force: true do |t| t.datetime "wk1_time" end I created a migration and it looks like this: class ChangeDateTimeDefault < ActiveRecord::Migration def change change_column :teams, :wk1_time, :default => DateTime.now end edn When I run rake db:migrate I get an error. Is my syntax wrong or am I missing something else? 回答1: Yes, you are missing the type : class

Rails sunspot-solr - words with hyphen

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using the sunspot_rails gem and everything is working perfect so far but: I'm not getting any search results for words with a hyphen. Example: The string "tron" returns a lot of results(the word mentioned in all articles is e-tron) The string "e-tron" returns 0 results even though this is the correct word mentioned in all my articles. My current schema.xml config: <fieldType name="text" class="solr.TextField" omitNorms="false"> <analyzer type="index"> <tokenizer class="solr.StandardTokenizerFactory"/> <filter class="solr

How to access JSON in Rails?

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have the following JSON params. Started POST "/tickets/move.json" for :: 1 at 2015 - 01 - 30 15 : 30 : 13 - 0600 Processing by TicketsController #move as JSON Parameters : { "_json" =>[{ "id" => "1" , "col" => 1 , "row" => 1 }, { "id" => "2" , "col" => 2 , "row" => 2 }, { "id" => "3" , "col" => 2 , "row" => 1 }, { "id" => "4" , "col" => 4 , "row" => 1 }, { "id" => "5" , "col" => 5 , "row" => 1 }], "ticket" =>{}} How can I access them, as I would with regular rails params? 回答1: That's a regular params hash. Rails is usually smart

Image urls for Rails 4 + Less not including the hash

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a Rails 4 application and am using the less-rails gem. In main.css.less , I add a background image to the site using: body { background-image: image-url("background.jpg"); } Everything works fine locally, but when I push up to my server with precompiled assets, the image url is not updating to include the hash. That is, the image now lives at public/assets/background-074c0b767cd8cfb2da93b37ea3596326.jpg but my css file still says url(/assets/background.jpg) . The link below seemed very promising, but none of the recommended solutions

Rails form with ajax and non-ajax buttons

匿名 (未验证) 提交于 2019-12-03 08:56:10
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a form_for an @object with two buttons. While the first button renders the 'show action', the second button renders the same form again. So I'd like the latter to be ajax-handled. Is it possible to have a non-ajax button and an ajax button in the same form or do I have to change strategy? Maybe I need a form_for with 'remote: true' so that both the buttons are ajax but then, how would I manage the first button to render the proper 'show view'? Or maybe the only real solution is to have two different forms? Thank you. 回答1: You could

ruby on rails - how to make relationship works in route, controller, view ? has_many, belongs_to

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am struggling to get my relationship in rails to work. I have a User,Gallery,Comment model class Gallery has_many :comments belongs_to :user end class User has_many :comments has_many :galleries end class Comment belongs_to :gallery belongs_to :user end now what should i do in the routes, controller and views to link this all up ? please help me ? its quite confusing finding out the answers. If can, I dont want it to be nested like in the railscast, but i want for each model, eg gallery i can input user, eg comment i can find and input the

SaaS billing for Rails app: Chargify, PayPal or…?

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am in my sophomore year of programming in general and Ruby on Rails more specifically. I have created several apps and finally have one that I would like to start charging for. I have never implemented something like this before and I feel like (from what I have read) most of the docs provided are a bit over my head. I don't mind diving in but before I did I wanted to get some opinion from those more experienced about what is the simplest way to implement a model for charging my User a month fee for use. Two notes: My App contains Users

Rails 4 with MailCatcher and Devise gems

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have an app with gem Devise. I need to confirm registration by email. In config/environment.rb I added this ActionMailer :: Base . delivery_method = : smtp ActionMailer :: Base . smtp_settings = { : address => "smtp.gmail.com" , : port => 587 , : domain => "gmail.com" , : authentication => 'plain' , : user_name => "myappname@gmail.com" , : password => "mypassword" } In config/environment/development.rb added: config . action_mailer . default_url_options = { : host => 'localhost:3000' } config . action_mailer . delivery_method = :

Rails: default scoping being cached by query cache?

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I got a default scoping like this which is dynamic: default_scope : conditions => [ "departure_date >= ?" , DateTime . current . beginning_of_day ] When I use this code the first day is ok. Lets say first day is 28-03-2011 But the next day seems like it's still using "departure_date >= 28-03-2011" Is my default scoping being cached? 回答1: The problem is that that code is only being executed once , when your app is loaded, and thus the actual date isn't changing. You need to change it to load lazily: default_scope lambda { { :

Labels for radio buttons in rails form

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: My question is similar to this one but for a Rails app. I have a form with some radio buttons, and would like to associate labels with them. The label form helper only takes a form field as a parameter, but in this case I have multiple radio buttons for a single form field. The only way I see to do it is to manually create a label, hard coding the ID that is auto generated for the radio button. Does anyone know of a better way to do it? For example: true %> Email SMS This generates something like: Contactmethod Email SMS What I want: Email