Rails

Ruby on Rails plural (controller) and singular (model) convention - explanation

匿名 (未验证) 提交于 2019-12-03 09:06:55
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: As per Ruby on Rails convention, controller names get pluralized while model names are singular. Example : a Users controller, but a User model. rails generate controller Users rails generate model User name:string email:string Now open migration file class CreateUsers Here table name is plural (users). So my question is - Why table name is plural (users) even though the model name is singular (User)? 回答1: Ruby on Rails follow linguistic convention . That means a model represents a single user, whereas a database table consists of many users

bundle install returns “Could not locate Gemfile”

匿名 (未验证) 提交于 2019-12-03 09:06:55
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm new to Rails and am currently working through a guide. The guide states: Use a text editor to update the Gemfile needed by Bundler with the contents of Listing 2.1. source 'https://rubygems.org' gem 'rails', '3.2.3' group :development do gem 'sqlite3', '1.3.5' end # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', '3.2.4' gem 'coffee-rails', '3.2.2' gem 'uglifier', '1.2.3' end gem 'jquery-rails', '2.0.0' group :production do gem 'pg', '0.12.2' end We then install and

Rails no implicit conversion of Symbol into Integer

匿名 (未验证) 提交于 2019-12-03 09:06:55
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to create a private method that does some counting based on some database data as follows. class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception before_action :moderation_count private def moderation_count @count = ''; @count[:venues_pending] = Venue.where(:is_approved => 0).count.to_i @count[:venues_rejected] = Venue.where(:is_approved => 2).count.to_i @count[:venue_photos_pending] =

Ruby on Rails Application coult not include stylesheet nor js

匿名 (未验证) 提交于 2019-12-03 09:06:55
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Im working at a windows 8.1 64bit computer and jetzt succeed in creating a scaffold when i found the next problem .... these are the commands i executed: rails new obs cd obs rails generate scaffold Customer name:string rake db:migrate rails s but i cant open the window because of this error: TypeError: Das Objekt unterstützt diese Eigenschaft oder Methode nicht. Rails.root: C:/Users/Adrian/Documents/Bumblebee Application Trace | Framework Trace | Full Trace app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb

Rails 4 - Do not scope if conditions

匿名 (未验证) 提交于 2019-12-03 09:06:55
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to create a scope with some conditions, with one returning not a specific scope. For now, this solution works: scope :my_scope, ->(my_var) { scope = where('TRUE') if my_var.condition1? scope = scope.where({ :some_condition => :some_value }) end if my_var.condition2? scope = scope.where({ :some_condition => :some_value }) end scope } Is there any other better solution to do this ? Regards 回答1: In Rails 4, you can simply use all : scope :my_scope, ->(my_var) { if my_var.condition? where(some_condition: :some_value) else all end end 文章来源

How to downgrade application from Ruby 2.0.0 to 1.9.3

匿名 (未验证) 提交于 2019-12-03 09:06:55
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: My application is using Ruby 2.0.0-p247 but I need to downgrade to 1.9.3 (a custom module that's critical to my application doesn't work in 2.0.0 but does in 1.9.3). To do this I updated my gemfile with ruby '1.9.3' in the command line i typed: rvm use 1.9.3 I also edited the .ruby-version file and replaced it's contents with: 1.9.3 I ran bundle install and then tried to start the application by typing: rails s It tries to start up but then gives a segmentation fault (long time since i saw one of those). The error outputted is pasted below.

Rails 3 Polymorphic Association between one MongoMapper model and one/many Active Record model/s

匿名 (未验证) 提交于 2019-12-03 09:06:55
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a Record model (Active Record) that stores some custom logs. Record is in polymorphic association with all the other model in my app, and I can effectively log what I want hooking my Record methods in the other controllers. What I need: To have the logs in a separate database. So I have to: Be able to manage two different databases in my apllication (one is Postgres/ActiveRecord and the other one is MongoDB/MongoMapper) Generate a polymorphic association between my Record model, now with MongoMapper, and the rest of my Active Record

rails:3 Devise signup Filter chain halted as :require_no_authentication rendered or redirected

匿名 (未验证) 提交于 2019-12-03 09:05:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using Devise in my site I create admin namespace and giving functionality of create user by admin. my routes are as under devise_for :users,:has_many => :comments, :controllers => {:sessions =>'devise/sessions',:registrations => 'devise/registrations'} do get "/login", :to => "devise/sessions#new", :as => :login get "/signup", :to => "devise/registrations#new", :as => :signup get "/logout", :to => "devise/sessions#destroy", :as => :logout end when i click on add_user link which has signup_path causing following error: My Error Started

Rails cron whenever, bundle: command not found

匿名 (未验证) 提交于 2019-12-03 09:05:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to use whenever to execute a rake task onces a day. Im getting this error /bin/bash: bundle: command not found /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find bundler (>= 0) amongst [minitest-1.6.0, rake-0.8.7, rdoc-2.5.8] (Gem::LoadError) from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec' from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems.rb:1210:in `gem' from /home/app/.rvm

Ajax success callback in ruby on rails

匿名 (未验证) 提交于 2019-12-03 09:02:45
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Hi want to implement ajax in my ruby on rails tutorials and the controller will return an object on handling the ajax request. I dont know to handle the response in my javascript file. I want to update some div based on object returned in javascript file. Here is what I have written in my showcomments.js.erb $('.show_comment').bind('ajax:success', function() { $(this).closest('tr')="Something here from the object returned"); }); My link where ajax call is called is via this line of code <td><%= link_to 'Show Comment', :action => 'showcomment