ruby-on-rails-3

Ruby on Rails Method Mocks in the Controller

和自甴很熟 提交于 2020-01-16 21:53:14
问题 I'm trying to mock a method call to an outside API inside one of my rails controllers (in this case, Instagram.get_access_token) and I'm having some trouble. As written, the code is still calling the real Instagram.get_access_token method. How do I have the controller use my simple mock instead? sessions_controller.rb: class SessionsController < ApplicationController require 'instagram' include ApplicationHelper def auth_callback response = Instagram.get_access_token(params[:code], redirect

Creating a new rails 3 project over a proxy in windows

蹲街弑〆低调 提交于 2020-01-16 20:57:34
问题 My computer works on a proxy. So in order to install gems I use the following command gem install -p http//#{proxy-server}:#{port} rails If i use the normal gem install command, I get an error could not find gem . I installed rails 3.1 today and tried to create a new project. Half the way while creating the files, the generator started executing run bundle install and ended up giving the same error Fetching source index for http://rubygems.org/ Could not reach rubygems repository http:/

Multiple dynamic instances of bootstrap-timepicker

情到浓时终转凉″ 提交于 2020-01-16 19:01:06
问题 I am using the bootstrap-timepicker for rails and I am using it in a form helper. It works very well if there is only one instance of it. Here is a code fragment: <div class="bootstrap-timepicker input-append span2 offset0"> <%= f.label :to_hour %> <input id="timepicker1" type="text" class="input-small" value='12:15 PM'> <span class="add-on"><i class="icon-time"></i></span> </div> However it doesn't work when there are multiple instances of it in a single page. Essentially I have multiple

access ActionView helpers from inside the Model

十年热恋 提交于 2020-01-16 18:25:30
问题 I have a simple template system which calls a show_me method defined inside different classes of my model (kinda Widgets) when rendering a template. These widgets originally returned the html as a string. So in my erb I have somethink like this. <% @template.widgets.each do |widget| %> <%= widget.show_me %> <% end %> As the views of the widgets became more complex I start using partials to render them, calling the ActionView::Base render method from inside my widgets (please don't throw up

how to collect through multiple sub categories

强颜欢笑 提交于 2020-01-16 14:18:09
问题 What's the rails way to see posts nested beneath several associative models that a user habtm? @user = current_user @user_clubs = @user.clubs #user is a member of many clubs (habtm), clubs have many events to post a quantity of products to @uc_products = @user_clubs.collect {|a| a.products} # clubs have many products (and categories, haven't implemented yet) (with title, description, etc) # @ucp_posts = @uc_categories.collect {|a| a.posts} # products have many posts (product_id, quantity, &

Rails mailer / smtp - potential security issue?

自闭症网瘾萝莉.ら 提交于 2020-01-16 13:27:53
问题 When using SMTP settings in Rails for sending e-mail, you need to provide a username and password for it to send email from your account. But isn't it a little dangerous to put your password to the site's email account in plain text in your code? Is there a more secure way to do this? config.action_mailer.smtp_settings = { :address => "address_here", :port => 'port_#_here', :domain => "example.com", :authentication => :plain, :user_name => "user@example.com", :password => "foobar", :enable

Heroku Production Error: PG::Error: ERROR: relation “users” already exists error

老子叫甜甜 提交于 2020-01-16 12:07:37
问题 Is deploying to Heroku typically like pulling teeth? I've been trying for a week now and it's error after error. I've contacted Heroku support and they suggested I try stackoverflow. So here it goes. I've just upgraded my Devise to 2.0 schema following the guide: https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style . See the codebase here: www.github.com/apane/blogit_blog I now have the following error (this should be the last of em') -- create

Heroku Production Error: PG::Error: ERROR: relation “users” already exists error

痴心易碎 提交于 2020-01-16 12:06:05
问题 Is deploying to Heroku typically like pulling teeth? I've been trying for a week now and it's error after error. I've contacted Heroku support and they suggested I try stackoverflow. So here it goes. I've just upgraded my Devise to 2.0 schema following the guide: https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style . See the codebase here: www.github.com/apane/blogit_blog I now have the following error (this should be the last of em') -- create

Added submit button calls the earlier button's function itself

那年仲夏 提交于 2020-01-16 11:59:12
问题 I'm working on Rails 3 app. Here a view displays all the excel files uploaded by user. A button to execute all the checkbox selected files was already present with delete for each file separately . Now I'm supposed to add a 'delete' button to delete the selected files . I've added the button n modified the function called by this form jus to display "in execute" and "in delete" for now to check if the second 'delete' button is functioanal. But every time delete is clicked it prints "in

Rails based simple AJAX calculation fxn seems harder than it should be

荒凉一梦 提交于 2020-01-16 11:56:46
问题 I feel like there is a large step from where Rails tutorials end and where I can actually use it to do what I need. This is manifesting itself in this relatively simple case: I want a page that takes inputs and calculates a volume. Ideally, this would do it with AJAX because it always irritates me when a simple page makes me reload it. I've been doing this in IRB with: radius = 25; length = 0.15;( radius**2) * Math::PI * length *1e-3 # radius in microns, length in meters, answer in