ruby-on-rails-3.1

Redirect user after log in only if it's on root_path

[亡魂溺海] 提交于 2019-11-27 01:57:41
问题 I have a root_path on my Rails application that is not user-protected i.e. it's a simple portal homepage, with a login form. After the users log in, I'd like it to go to dashboard_path . I've done this: def signed_in_root_path(scope_or_resource) dashboard_path end This apparently should be used when an user signs in, and I don't want it to go to the root_path , while still keeping the user going back to a previous page if it tries to hit a restricted area and it's either timed out or not

How does one reference compiled assets from the controller in Rails 3.1?

青春壹個敷衍的年華 提交于 2019-11-27 01:49:09
问题 I'm using the PDFkit in my controller to build out a series of PDFs, zip them up, and then send them to the user. In order to control the output styles, I tell PDFKit which stylesheets to use during content generation. I need to pass along the file reference of the CSS file. Since Rails is now compiling and renaming my stylesheets, I'm not sure how to reference the compiled CSS asset inside my controller. Here's what I used to do: InvoicesController < ApplicationController def download kit =

Rails 3.1 absolute URL to an image

房东的猫 提交于 2019-11-27 01:15:37
问题 I'm using Rails 3.1. I'm trying to figure this out, and to my surprise, it is starting to seem that rails does not come with this method at all. Maybe im wrong. Can anyone show how I can get a full absolute URL to an image? I use asset_path(image.png) which gives me the relative path to use within the app. I tried doing a root_url + asset_path(image.png) but that just gives me a http://localhost:3000//assets/image.png with the double slashes Anyone have an efficient way of doing this? 回答1:

How do I use Controller specific stylesheets in Rails 3.2.1?

微笑、不失礼 提交于 2019-11-27 00:38:15
问题 Using Rails 3.2.1 I created a simple controller called Home using the command: rails g controller Home index And it created a new controller and view for me: Notice how there are two stylesheets, one "Application" and one "Home". I can't find any documentation to support this assumption but I'm guessing you put styles that will only be applied to the "Home" views, in the Home.css.scss file, correct? So as a test, I added in some global styles to Application.css.scss.erb and ran the

How to avoid precompiled assets being served in development mode?

萝らか妹 提交于 2019-11-27 00:01:41
问题 I prefer not to concatenate JavaScript files in development mode, but serve them as individual files. So I configured: development.rb: config.assets.compress = false config.assets.debug = true config.assets.compile = true In my /app/assets/javascript directory I have: reviews.js reviews/ foo.js bar.js reviews.js: //= require jquery //= require jquery_ujs //= require_tree ./reviews I include the JavaScript using <%= javascript_include_tag "reviews" %> in my layout. The generated page correctly

Add a new asset path in Rails 3.1

一世执手 提交于 2019-11-26 23:57:28
问题 Does anyone know how to add another folder to the asset pipeline in Rails 3.1? I'd like to serve app/assets/fonts the same way app/assets/images is served. Update: 5-7-2013 Just to add some clarification for future people who find this question to explicitly add an asset path, in your application.rb file: config.assets.paths << "#{Rails.root}/app/assets/fonts" However, since the above path is under app/assets you don't have to add it explicitly, you just need to restart your rails app so

Rails routes with optional scope “:locale”

感情迁移 提交于 2019-11-26 23:20:44
问题 I'm working on a Rails 3.1 app and I'd like to set specific routes for the different languages the app is going to support. /es/countries /de/countries … For the default language ('en'), I don't want the locale to be displayed in the url. /countries Here is the route definition I've set. scope "(:locale)", :locale => /es|de/ do resources :countries end It works great, until I try to use a path helper with 'en' as the locale. In the console : app.countries_path(:locale => 'fr') => "/fr

Rails asset pipeline: Standard way for including all /vendor/assets/javascripts/?

我是研究僧i 提交于 2019-11-26 22:38:05
问题 I've been transitioning an app to Rails 3.1 (and now on to 3.2) and watched the Railscast on the asset pipeline. I moved all of my third-party jquery plugin files to the /vendor/assets/javascripts/ directory. In my /app/assets/javascripts/application.js I have the following: //= require jquery //= require jquery_ujs //= require_tree . //= require_self I realized the require_tree . call only loads the tree for the /app/assets/javascripts/ directory. (Is that correct?) What's the best way to

Best way to highlight current page in Rails 3? — apply a css class to links conditionally

旧城冷巷雨未停 提交于 2019-11-26 22:36:42
问题 For the following code: <%= link_to "Some Page", some_path %> How do I apply a css class current using the current_page?‎ helper method? Or if some other better way is available? 回答1: In app/helpers/application_helper.rb def cp(path) "current" if current_page?(path) end In your views: <%= link_to "All Posts", posts_path, class: cp(posts_path) %> Basically write a simple wrapper around it. Additionally you could extend the method to allow additional classes to be applied by adding arguments.

Cookies do not persist in Rspec on rails 3.1

女生的网名这么多〃 提交于 2019-11-26 21:36:47
问题 This is a problem with the cookies collection in a controller spec in the following environment: rails 3.1.0.rc4 rspec 2.6.0 rspec-rails 2.6.1 I have a simple controller spec that creates a Factory user, calls a sign in method which sets a cookie, and then tests to see if the signed in user may access a page. The problem is that all cookies seem to disappear between the authentication cookie being set and the "show" action being called on my controller. My code works fine when run in a