ruby-on-rails-3.1

Force SSL for specific routes in Rails 3.1

a 夏天 提交于 2019-12-05 15:37:25
问题 I need to force SSL on all routes in my application except for landing#index . In config/application.rb , I have: config.force_ssl = true Then in landing_controller.rb , I have: force_ssl :except => :index However, all routes are still being redirected to https . Does anyone know how to conditionally force SSL in a Rails 3.1+ application? Solution: Add the following to your Gemfile : gem 'rack-ssl-enforcer' Add the following to your config/application.rb : config.middleware.use Rack:

How can I connect to MySQL in Ruby on Rails?

£可爱£侵袭症+ 提交于 2019-12-05 15:27:16
问题 I am really new in Ruby on Rails. I have read this tutorial and it sounds really easy. But how can I connect to my database (MySQL) or what does Rails use? In php I'd use... mysql_connect("...","...","..."); mysql_select_db("..."); I have searched google and cannot find any useful tips. 回答1: You don't have to do those things manually, check this: http://guides.rubyonrails.org/configuring.html#configuring-a-database 回答2: Have a look into the configuration file config/database.yml You need to

Why does rake assets:precompile in development cause problems but not in my production environement

落爺英雄遲暮 提交于 2019-12-05 14:06:33
I have upgraded my app on heroku to a cedar stack so that the asset pipeline works. I have followed the instructions given in heroku's docs by choosing to compile assets locally. This has created a directory public/assets. Everything in production works perfectly(css, js, with no problems). Going back to my development environment seems to cause the js to not function properly. In environments/production.rb config.serve_static_assets = false config.assets.compress = true config.assets.compile = true config.assets.digest = true In environments/development.rb config.assets.compress = false

Ruby on Rails: How would i stay on the same page if the post is not saved?

风格不统一 提交于 2019-12-05 12:40:57
问题 def create @addpost = Post.new params[:data] if @addpost.save flash[:notice] = "Post has been saved successfully." redirect_to posts_path else flash[:notice] = "Post can not be saved, please enter information." end end If the post is not saved then it redirects to http://0.0.0.0:3000/posts , but i need to stay on the page, with text input fields so that user can input data. post model class Post < ActiveRecord::Base has_many :comments validates :title, :presence => true validates :content,

Why after_commit not running even with use_transactional_fixtures = false

喜夏-厌秋 提交于 2019-12-05 12:05:57
问题 Transactional fixtures in rspec prevent after_commit from being called, but even when I disable them with RSpec.configure do |config| config.use_transactional_fixtures = false end The after_commit callback does not run. Here is a rails app with the latest rspec / rails that I have produced the issue on: git://github.com/sheabarton/after_commit_demo.git 回答1: One way around this is to trigger the commit callbacks manually. Example: describe SomeModel do subject { ... } context 'after_commit' do

How to properly work with jQuery in Rails 3.1 asset pipeline?

陌路散爱 提交于 2019-12-05 11:30:19
问题 I'm working on a hobby app and using some jQuery. The results are fine at the moment, but I'm a jQuery noob and I assume that there are some significant improvements that I can make to the code structure. Putting aside Coffescript for the moment, one thing that I've been wondering is how to properly use the model-specific .js files in the asset pipeline. For example, when working with my User model, I may have some code that I want to have run when the document is ready. Let's say I put that

Eager loading association but limit return

痞子三分冷 提交于 2019-12-05 11:08:14
It seems like a simple query but I just can't nail it. Basically it boils down to the age old concept of a categories having posts. The expected associations are in place, a category has_many posts whilst a post belongs to a category. I want to retrieve all the categories with their posts but limit the number of posts to 10. Any ideas? This isn't something that you can do with raw SQL as LIMIT's are on the total dataset size, not anything else. The only way of doing this purely by SQL is to create a fake id column in your join and filter than when it comes out which is something that

Rails javascript database queries

两盒软妹~` 提交于 2019-12-05 10:43:25
问题 How do I do a PUT, POST or DELETE call from javascript? I've collected some data using jquery drag and drop. How do I then send this to the database? I think I might be able to use jQuery.ajax but can't work out how exactly. Any pointers appreciated. Solution: This is the javascript that works $(document).ready(function() { $.ajax({ type: "PUT", url: "/articles/8", // should be mapped in routes.rb data: {articles:{name:"New Name"}} }); }); But it doesn't change the name of article 8 to New

Devise + Active Admin Redirect

岁酱吖の 提交于 2019-12-05 09:01:57
I am having trouble setting up the redirect for my application. Users should go to their profile (users/show) and admins should go to the admin dashboard.. How do i set this up? Currently getting the following error: NameError in ActiveAdmin::Devise::SessionsController#create undefined local variable or method `admin' for #<ActiveAdmin::Devise::SessionsController:0x007febe12667e8> Application controller def after_sign_in_path_for(resource_or_scope) if admin redirect_to admin_dashboard_path else @user end end end You don't have an admin variable to access, you need to check what the parameter

Bourbon vs Twitter Bootstrap for Rails 3.1

不问归期 提交于 2019-12-05 08:40:33
I am looking around at different stylesheet frameworks to pick out which one to use in my Rails 3.1 applicaiton. Twitter Bootstrap looks really cool, but I also see that Bourbon is becoming very popular too. Can anyone give a comparison and pros and cons of each? I am guessing it won't be a good idea to use them both, right? You could absolutely use both... Each are a set of SASS mix-ins and CSS classes. You may run into some overlap, but there's nothing that prevents you from using both 来源: https://stackoverflow.com/questions/7639394/bourbon-vs-twitter-bootstrap-for-rails-3-1