ruby-on-rails-3.2

Possible to add a form into another models view in rails

不打扰是莪最后的温柔 提交于 2019-12-11 15:01:43
问题 I have a very small application I ma building in rails. It is a simple weight tracker app. I have created a User model which has a sign up page. Once the user logs in they are redirected to the user#show view. Here is the user controller so far: class UsersController < ApplicationController before_filter :authenticate_user! def show @user = current_user end end I have 2 other models one is a Weight model and the other a Goal model, I would like it so what when a user signs up they are

how to view all associated data among models

人走茶凉 提交于 2019-12-11 15:01:13
问题 I've spent awhile searching for this but I'm not really sure how to ask what I want to know and I think that's my biggest problem here :p I have the following data models: User has_many :student_groups, dependent: :destroy Student_Group belongs_to :user has_many :students, dependent: :destroy Student belongs_to :student_group I want to view all students across all a given user's student_groups - how to do this? At the moment, my students#index route is as follows: student_group_students GET

activeadmin custom render if

浪尽此生 提交于 2019-12-11 14:10:00
问题 My below code ActiveAdmin.register Question do belongs_to :topic, :optional => true controller do def index @topic = Topic.find_by_id params[:topic_id] if @topic @questions = @topic.questions render 'settings/questions/_by_admin', :layout => 'active_admin' return end end end end is throwing NoMethodError in Admin/questions#index Showing /home/amol/.rvm/gems/ruby-1.9.2-p290@xxx/gems/activeadmin-0.5.0/app/views/layouts/active_admin.html.arb where line #1 raised: undefined method `base' for nil

Rails: How to handle existing invalid dates in database?

我只是一个虾纸丫 提交于 2019-12-11 13:59:27
问题 First, this is directly related to my other question: How to gracefully handle "Mysql2::Error: Invalid date" in ActiveRecord? But I still do not want to jump through all the loops of writing migrations which fix dates. That won't be the last table with invalid dates and I need some more generic approach. So here we go: I'm using a legacy MySQL database which contains invalid dates, sometimes like 2010-01-00 or 0000-04-25... Rails does not load such records (older versions of Rails did). I do

Using Rails default exception translation in specs

北城以北 提交于 2019-12-11 13:57:22
问题 My controller is throwing ActiveRecord::RecordNotFound which is what to be expected to be translated into 404. Now I want to test this behaviour in my controller spec, but it gets exception rather than response_code equal to 404. How to make it get this code instead? 回答1: When Rails raise a ActiveRecord::RecordNotFound it simply telling you that ActiveRecord was not able to find a resource in your database (usually using find ). It is your responsability to catch the exception and to do

Does invoking multiple tasks from a parent rake loads environment for each of them

拜拜、爱过 提交于 2019-12-11 13:54:06
问题 If I have one rake which invokes multiple other rakes. Once I initiate the parent rake rake myapp:main Then invokes done within the rake would load environment for each task or its just one time activity done while running rake myapp:main ? namespace :myapp do desc "Main Run" task :main => :environment do Rake::Task['myapp:task1'].invoke Rake::Task['myapp:task2'].invoke end task :task1 => :environment do # Does the first task end task :task2 => :environment do # Does the second task end end

How do I grab meta data from other websites and display on mine in ruby on rails?

时光怂恿深爱的人放手 提交于 2019-12-11 13:50:01
问题 When using FB or Google + I can paste a link of any website into the status update box and it will instant load information about that website with the option of flicking through thumbnail images. How can I go about achieving this in ruby on rails? All my searches seem to bring up php methods on how to do this. For grabbing video data info I use the Ruby Open Graph Protocol gem. Is there any thing for grabbing data the way FB and G+ do? If not is there a standard way this is done in rails

How to embedd video in WYSI HTML5 editor

℡╲_俬逩灬. 提交于 2019-12-11 13:47:14
问题 I am developing a tutorial website in which I want to display textual as well as video tutorial for users. To enter information and for formatting purpose I have used bootstrap-wysihtml5-rails editor. Using this editor I am able to add links, images and perform all basic functionality. Now I want to add a button in the editor to add a video link which help me to add video path of my local video storage. I searched through many links but could not get the solution as required for my problem.

How to call a Capistrano's task within another Capistrano's task?

时光怂恿深爱的人放手 提交于 2019-12-11 13:28:21
问题 I'm trying to create a basic task for copying and linking database.yml file into my app, but I can't figure out why it s not working. I'm using Capistrnao 3.1 This is my lib/capistrano/tasks/databases.cap file : namespace :db_access do # Idea : https://github.com/capistrano/sshkit/blob/master/EXAMPLES.md desc 'Copy production database.yml from local workstation' task :copy_production do on roles :all do execute :mkdir, '-p', "#{shared_path}/config" upload! 'config/deploy/production.database

Passenger 3.0.17 + Nginx 1.2.4 + “Content-Length” Header = 502 Bad Gateway

混江龙づ霸主 提交于 2019-12-11 12:09:05
问题 I have just run across an issue where setting response.headers['Content-Length'] in a Rails 3.2.2 application causes Nginx to throw a "502 Bad Gateway" error. I have an action in a controller that uses the send_data method to send raw JPEG data contained within a variable. Before, I had a problem with some browsers not downloading the entire image being sent and discovered that no Content-Length header is being sent, so I decided to use the .bytesize property of the variable containing the