ruby-on-rails-3.2

Collecting first segments of all routes in rails 3

那年仲夏 提交于 2020-01-03 05:26:17
问题 I'm trying to implement routes where the first segment is the profile's alias or id: resources :profiles, :path => '' do ... end And I need to validate that alias is not already taken by first segments of other(higher) routes. What I have now is: validates :alias, :exclusion => {:in => Rails.application.routes.routes.map{|r| r.path.spec.to_s.split('(').first.split('/').second}.compact.uniq }, .... In development everything is ok. In production Rails.application.routes.routes.map... returns

NameError: uninitialized constant ActionController::Dispatcher

本秂侑毒 提交于 2020-01-03 04:04:08
问题 Found a similar post here but I am running a Mac so the first solution does not exactly apply and the second didn't work for me. Running Mac OS 10.7.2, Xcode 4.2.1, rvm 1.10.1 using ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0] I believe the issue to due with rvm, however I do not know how to fix it $ rails new dispatch_me $ rails generate controller demo index $ rails console Loading development environment (Rails 3.2.0.rc2) 1.9.3-p0 :001 > env = {} => {} 1.9.3-p0 :002 > env

UserMailer with Devise

拈花ヽ惹草 提交于 2020-01-02 23:09:34
问题 am using my custom mailer UserMailer to send emails. It works perfect in development, but in production i get error 500, that is when am trying to retrieve my password on forgetting. here is what is in the production logs in the production mode Processing by Devise::PasswordsController#create as HTML Parameters: {"utf8"=>"✓","authenticity_token"=>"xxxxxxxxxxxxxxx", "user"=>{"email"=>"sam@gmail.com"}, "commit"=>"Send me r$ Completed 500 Internal Server Error in 2ms NameError (uninitialized

Rails 3.2 - haml vs. erb. Is haml faster? (february 2012)

▼魔方 西西 提交于 2020-01-02 00:52:14
问题 I am working on a project and I am still thinking about using HAML (beautiful code, less size of view files) instead of classic ERB template. My worries why I didn't do it yet are the speed of generating views - I read an articles/benchmarks and there was almost always HAML slower than ERB - but the truth is, that the articles are 2-3 years old. So my question is, how looks the comparison these two template systems now, in the start of 2012? 回答1: Here are some benchmarks from someone in Nov

How to serialize - deserialize params hash object?

房东的猫 提交于 2020-01-01 17:19:09
问题 how would I do such a thing? I want to be able to store the params object into a string attribute of a model, and be able to deserialize it into params hash object again, how would I do this in ruby? or is there an out of the box solution in rails? 回答1: Active Record can serialize any object in text columns using YAML. To do so, you must specify this with a call to the class method serialize. This makes it possible to store arrays, hashes, and other non-mappable objects without doing any

Nested Model Forms - Railscast #196 revised - Adding fields via jQuery not working

不打扰是莪最后的温柔 提交于 2020-01-01 14:36:01
问题 I was following the Railscast #196 revised and everything went basically fine, but I am not able to add new fields to the nested form. The "remove fields" function works nicely, but after click on "link_to_add_fields", the browser jumps to the top of the page, and no new field appears. There are already a ton of questions to this railscast, like here or here, and I tried to read all of them, but most of them are referring to the original casts from 2010. I am stuck for hours now, and I can't

Find records that were created closest to the current date

纵饮孤独 提交于 2020-01-01 10:13:27
问题 I would like to get the records that have their created_at date closest to the current date. How can I do this with active records' where clause? 回答1: You could find the closest record in the past with something like: Record.where("created_at <= ?", Date.today).order_by("created_at DESC").limit(1) Similarly, you can have the closest record in the future Record.where("created_at >= ?", Date.today).order_by("created_at ASC").limit(1) And then compare wich one is the closest to current date...

Rails path-helpers doesn't work in js.coffee.erb

牧云@^-^@ 提交于 2020-01-01 10:02:44
问题 In my Rails 3.2 app (Ruby 1.9) I get following error when using path helpers in Coffeescript. undefined local variable or method `new_user_session_path' In my partial _usermenu.html.haml that works fine: = link_to t('user.login'), new_user_session_path In my app/assets/javascripts/metamenu.js.coffee.erb that throws above error: $.get("<%= new_user_session_path %>") Isn't it possible to use x_path and x_url helpers in coffeescript erb's? 回答1: This is because you are not within the view context

testing with specs, capybara from railstutorial chapter 3 does not work (have_selector('title', :text => ' | Home'))

三世轮回 提交于 2020-01-01 08:44:45
问题 im working on ruby.railstutorial.org/ruby-on-rails-tutorial-book. Im using rails 3.2.7, spork, rspec, capybara, launchy and some guards :) i have a really weird problem in Chapter 3 with testing: It seems like the tests arent working for what is inside the <head> -Tag. If i put the <title> -tag inside the <body> -tag instead of the head-tag it works fine. Also it works when i put <h1> -tags above the <title> inside <head> -Tags. It is weird, isnt it? Please help me figur out. The example is

ActiveAdmin with CanCanAdapter causing infinite redirect on dashboard

人走茶凉 提交于 2020-01-01 05:18:50
问题 When using the CanCan adapter in ActiveAdmin 0.6.0. I have a resource working and authorization is working. However, when I go to /admin , the root ActiveAdmin page, it redirects to /admin and continues this forever. 回答1: If the user does not have access to a page, ActiveAdmin redirects to the Dashboard. If the user doesn't have access to the dashboard, this results in an infinite redirect. Solution is to give the user the ability to read the dashboard page. Place this in the ability model