ruby-on-rails-4.1

Bind rails server to 127.0.0.1 by default

…衆ロ難τιáo~ 提交于 2020-05-26 10:27:42
问题 I'd like to bind the rails server to 127.0.0.1, instead of 0.0.0.0 so its not accessible when I'm working from coffee shops. Is there a configuration file where I can specify this option so I don't have to pass the command line switch: rails server -b 127.0.0.1 ? 回答1: If you are searching for Rails 5 : Answer In Rails ~> 4.0 you can customize the boot section of the Server class: In /config/boot.rb add this lines: require 'rails/commands/server' module Rails class Server def default_options

TZInfo::DataSourceNotFound error starting Rails v4.1.0 server on Windows

不羁的心 提交于 2020-01-18 04:53:46
问题 I have created a new application using Ruby on Rails v4.1.0. When attempting to start a server or console on Windows, I am encountering the following error: $ rails server Booting WEBrick Rails 4.1.0 application starting in development on .... Exiting c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/tzinfo-1.1.0/lib/tzinfo/data_source.rb:199: in `rescue in create_default_data_source': No timezone data source could be found. To resolve this, either install TZInfo::Data (e.g. by running

TZInfo::DataSourceNotFound error starting Rails v4.1.0 server on Windows

﹥>﹥吖頭↗ 提交于 2020-01-18 04:53:04
问题 I have created a new application using Ruby on Rails v4.1.0. When attempting to start a server or console on Windows, I am encountering the following error: $ rails server Booting WEBrick Rails 4.1.0 application starting in development on .... Exiting c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/tzinfo-1.1.0/lib/tzinfo/data_source.rb:199: in `rescue in create_default_data_source': No timezone data source could be found. To resolve this, either install TZInfo::Data (e.g. by running

In Rails 4.1, how to find records by enum symbol?

非 Y 不嫁゛ 提交于 2019-12-29 16:08:30
问题 Assume I have this model: class Conversation < ActiveRecord::Base enum status: [ :active, :archived ] end How can I find all active conversations without using the numeric value of the enum or without having to iterate over each conversation? I tried doing Conversation.where(status: :active) , but it didn't yield any results. The only solution comes to mind is to iterate over all conversations and select the active ones, but it doesn't look like a good solution. Conversation.all.select {

Rails Spring breaking generators

*爱你&永不变心* 提交于 2019-12-28 13:41:47
问题 I'm setting up my first Rails 4.1 app, which comes with Spring, their new preloader. When I try to install Devise using their generator ( $ rails generate devise:install ), the command line just hangs and nothing gets generated. If I remove Spring from the gem file and try again, the Devise generator works. Anyone have any insight? 回答1: Check directories of some other projects that you were working on at that time, chances are that the generated files ended up there. spring seems to get

spring using by default

故事扮演 提交于 2019-12-25 03:59:07
问题 I upgraded rails to 4.1.0 & installed gem "spring" After it, I patched bundle exec spring binstub --all . Now, all my bin/* includes begin load File.expand_path("../spring", __FILE__) rescue LoadError end But, if I run, saying time spring rake -T & time rake -T times 1 second & 3 seconds! It seems that spring not used by default in my application. What's going wrong? It's bad thing that I need to write annoying spring ..command.. before any rake task, rails server or rspec. What I need to do

spring using by default

大城市里の小女人 提交于 2019-12-25 03:59:01
问题 I upgraded rails to 4.1.0 & installed gem "spring" After it, I patched bundle exec spring binstub --all . Now, all my bin/* includes begin load File.expand_path("../spring", __FILE__) rescue LoadError end But, if I run, saying time spring rake -T & time rake -T times 1 second & 3 seconds! It seems that spring not used by default in my application. What's going wrong? It's bad thing that I need to write annoying spring ..command.. before any rake task, rails server or rspec. What I need to do

wrong number of arguments (0 for 1) while create my user

自闭症网瘾萝莉.ら 提交于 2019-12-24 02:22:55
问题 I know there is a lot of question about that but I can't find an answer for my case. So, I build a Rails 4 API, I try to create a User with a post JSON request. Here some pieces of my code : user.rb : class User < ActiveRecord::Base acts_as_token_authenticatable has_secure_password belongs_to :current_position, :class_name => "Position", foreign_key: "position_current_id" has_many :positions searchkick locations: ["location"] def search_data attributes.merge location: [current_position

Rails 4.1 Nested Attributes and Fields For Getting Unpermitted Parameters and Not Saving

笑着哭i 提交于 2019-12-24 00:55:44
问题 Research: Rails 4.0 beta, fields_for not accepting pluralized model_name in one-to-many association, Rails 4 Nested Attributes with fields_for Don't Save to Database First, let's get the most common problem out of the way: incorrectly named attributes parameters for strong parameters. Mine is correctly plural. class AdultsController < ApplicationController ... def update authorize @user respond_to do |format| if @user.update_attributes(user_params) format.html { redirect_to unit_adult_path(

Are application helper methods available to all views?

房东的猫 提交于 2019-12-22 08:59:41
问题 Rails 4.1 Ruby 2.0 Windows 8.1 In my helpers/application_helper.rb, I have: def agents_and_ids_generator agents = Agent.all.order(:last) if agents agents_and_ids = [['','']] agents.each do |l| name = "#{l.first} #{l.last}" agents_and_ids << [name,l.id] end return agents_and_ids end end In my views/agents/form.html.erb, I have the following: <%= f.select :agent_id, options_for_select(agents_and_ids_generator) %> In my controllers/agents_controller.rb, I have the following: include