ruby-on-rails-3

rake undefined method `gsub' for nil:NilClass

我的梦境 提交于 2019-12-23 19:01:07
问题 I'm hoping there is someone out here with a few encouraging words and a little advice. I am using Ruby v1.9.2 p290 I've been setting up a new production server and I'm having a terrible time trying to get the new environment to work correctly. Everything is installed and now I'm trying to run rake , but it is giving me an error I can't make any sense of and can't find any internet help on. deploy@ip-10-99-66-30:~/pm$ rake -v --trace rake aborted! undefined method `gsub' for nil:NilClass /usr

How can I access cookies from a model in Rails 3

时光毁灭记忆、已成空白 提交于 2019-12-23 18:56:39
问题 I am using the Koala gem to interact with the Facebook API. In order to connect to the API, I need to pass my cookies to Koala. I want to do this in a model because I want to add additional data to the user from Facebook data during a before_create callback in the model. For instance, if a user has an active FB session, store their Facebook UID when creating their user row. How do I get at cookies from within a model? 回答1: Models should not be aware they're operating in a web environment.

Rails friendly_id pages still attainable by record id

六眼飞鱼酱① 提交于 2019-12-23 18:53:31
问题 I'am using the friendly_id gem in my rails app, to create nice clean url's. It's working out good, but the page are also attainable by te record id. Example: I've a record with 'name' as slug. This record has 1 for ID. So the page is attainable from 2 url's: domain.com/name and domain.com/1 I want only to use domain.com/name, so I dont want the page to be attainable from domain.com/1. Does anyone know how to accomplish this? 回答1: From the author himself (Google is your friend; this is a top

In Rails, should I enable serve_static_assets?

♀尐吖头ヾ 提交于 2019-12-23 18:53:17
问题 I am currently using Apache to proxy to Thin (using this article) None of my static assets work (e.g. stylesheets, javascripts). Is Apache supposed to be serving them or do I have to enable config.serve_static_assets in config/environments/production.rb ? If Apache is supposed to serve them, then what am I probably doing wrong? Here is my Apache config: <VirtualHost *:80> ServerName example.com ServerAlias www.example.com DocumentRoot /home/r/public_html/example/public RewriteEngine On <Proxy

return redirect_to in private controller method

余生颓废 提交于 2019-12-23 18:40:25
问题 Preface: I'm using devise for authentication. I'm trying to catch unauthorized users from being able to see, edit, or update another user's information. My biggest concern is a user modifying the form in the DOM to another user's ID, filling out the form, and clicking update. I've read specifically on SO that something like below should work, but it doesn't. A post on SO recommended moving the validate_current_user method into the public realm, but that didn't work either. Is there something

Rails generate forms based on model

若如初见. 提交于 2019-12-23 18:39:24
问题 When running the initial scaffold command, it auto generates a form for you based on your model. Is there any way to rerun this when you are generating a migration? It would be awesome to be able to type rails g view user or w/e that would update your views according to your new model fields. 回答1: https://github.com/justinfrench/formtastic Allows you to do this. 来源: https://stackoverflow.com/questions/10471174/rails-generate-forms-based-on-model

db:seed is throwing an error

我们两清 提交于 2019-12-23 18:36:20
问题 I'm using ruby 1.9.2 with rails 3.0.9. Whenever I try to execute rake db:seed it throws following error: rake aborted! uninitialized constant EmployeeCategory I've disabled threadsafe and enabled 'dependency_loading in config/application.rb file. config.threadsafe! unless $rails_rake_task config.dependency_loading = true But it is still not working. Here's the content of seed.rb file StudentCategory.destroy_all StudentCategory.create([ {:name=>"OBC",:is_deleted=>false}, {:name=>"General",:is

How do I use Capybara get, show, post, put in controller tests?

拟墨画扇 提交于 2019-12-23 18:25:22
问题 I'm just not sure what the exact way to word it is.. This tells me 'No response yet. Request a page first.' it "should list searches" do get 'index' page.should have_selector('tr#search-1') end Is it meant to be like this instead? it "should list searches" do get 'index' do page.should have_selector('tr#search-1') end end That way doesn't seem to actually test anything though. What's the correct way? 回答1: According to this, Capybara doesn't support PUT and DELETE requests with the default

before_filter set_locale except controller

风格不统一 提交于 2019-12-23 18:22:53
问题 My routes.rb MyApp::Application.routes.draw do scope '(:locale)' do #all resources here end namespace :blog do resources :posts, :only => [:index, :show] end end My application_controller.rb class ApplicationController < ActionController::Base # # before_filter :set_locale private def default_url_options(options = {}) {locale: I18n.locale} end def set_locale #code for detect locale here end # # end All the resources inside scope '(:locale)' is working fine. However I don't want use locale

dots in URL routes with namespace rails 3.1

心已入冬 提交于 2019-12-23 18:15:00
问题 I have this in routes.rb root :to => "posts#index" devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } resources :users, :only => :show resources :boards resources :posts do resources :comments end namespace :users do resources :posts do get :posts, :on => :member end resources :boards do get :boards, :on => :member end end rake routes: boards_users_board GET /users/boards/:id/boards(.:format) {:action=>"boards", :controller=>"users/boards"} users_boards