spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » RUBY ON RAILS » Page 4
Crop Video and Audio files when uploading in a Rails app using paperclip
With paper clip you should use the following command of ffmpeg to generate the crop audio/video: ffmpeg -ss 0 -i file.mp3 -t 20 file.wav Look at the -t and -ss arguments, it will do what you want: -t duration Restrict the transcoded/captured video sequence to the duration specified in seconds. hh:mm:ss[.xxx] syntax is also supported. -ss position Seek to given time position in seconds. hh:m

Categories : Ruby On Rails

Mailboxer attachments via CarrierWave
I just added to initializers/mailboxer.rb ... class AttachmentUploader < AllAttachmentUploader end It allow me inherit from AllAttachmentUploader to AttachmentUploader which was defined in Mailboxer.

Categories : Ruby On Rails

Object Oriented Modelling Advice
My thoughts are that Products should be a module(?), as other classes 'have products', as opposed to 'are products’? I'd prefer to make Product an AR::Model. In fact it is a separate entity with its own behavior and state. It is a core model of your app, if I understood everything right. I’m unsure that I even need a Product library (would it just be products.all?)? If you will

Categories : Ruby On Rails

"Rails way" to execute a seml-complex query
Probably the easiest way to go through ActiveRecord would be something like this: Exam.where(:user_id => 1, :quiz_id => 114).select(%q{ sum(case when is_graded then 1 else 0 end) graded, sum(case when is_canceled then 1 else 0 end) canceled, sum(case when is_graded IS NULL and is_canceled IS NULL then 1 else 0 end) in_progress })[0] That will give you an Exam instance in result but

Categories : Ruby On Rails

Form_tag 'create' vs '/create'
form_tag needs whatever is necessary to find a path for sending data. action: 'create', which is resolved to {action: 'create'}, a Hash, invokes a routing system (with rules defined in routes.rb) to find a route in the same controller (the current view is in) for create action. Otherwise, it's more commonly used with path helpers, returning paths as strings. When you specify a string manually, i

Categories : Ruby On Rails

Rails 4.1.7 Heroku Error: (No route matches [GET] “/”)
You don't have a route that matches to your root path ('/'). Which means when you go to your heroku and enter myheroku-app.com Your application doesn't know which controller#action to send as a response. However, if you put in myheroku-app.com/pages/landing_page (by looking at your routes), you will see your landing_page. If pages is the name of your controller, and landing_page is your action

Categories : Ruby On Rails

Get "ActionView::MissingTemplate" error, when I post json to rails controller from angular
You are not explicitly rendering anything in the test method so rails is looking for a template to send back as a response. However, you don't have a json template in your api/v1/dropdowns/ folder (I think it will look for a file called test.json in your case). You can solve this by either sending back a response explicitly, (check out this guide for more about rendering a response. def test

Categories : Ruby On Rails

rails inverse of using 'references' in generators
There's no way of knowing where to put it, you'd have to specify it. Such generators are designed to save time, and making such a thing saves too little or none. For instance, you'll have to specify explicitly the target class and whether it is has_one or has_many. That would subtract some of the usefulness of this, resulting in a very small positive or even a negative value. I assume you mean th

Categories : Ruby On Rails

Rails Association: Teacher Student Classes
Class is not a good name, ClassRoom is better class ClassRoom < ActiveRecord::Base belongs_to :teacher belongs_to :student # if I have well understand, this is the right association #some validations rules validates :<fieldname>, :<rule> => <value>, ... #callback like :before_save or :after_save, .... end class Teacher < ActiveRecord::Base has_many :stude

Categories : Ruby On Rails

Rails: Dry content_for before yield
You can use helper like this: def yield_something_once unless @yielded_something @yielded_something = true content_for :something end end Or just use content_for(:smth, '') right after yield :smth to clear it.

Categories : Ruby On Rails

Queuing Requests(delayed job) on downloading large CSV size file as background process
The thing you're trying to do defeats the purpose of DelayedJob. When a user makes a request, the server should make a response in order to fullfill it. The problem is, that some requests take quite a lot of time to complete, and the user has to hang on and wait until it's done. A classic case – massive email delivery, but there are others, as you've mentioned, like data suite generation. W

Categories : Ruby On Rails

Iterate over an Active Record Relation in Rails 3.2
Problem is here: <%= @items.each do |r| %> This line of code iterates over each of the relations and due to the '=' you output its content. Change it to: <% @items.each do |r| %> and you are good to go!

Categories : Ruby On Rails

access token request with box api
First Your RestClient.post() function incorrect. Because it is a post you should not have params: hash but rather the payload itself. This is because post requests don't have params in the url, but rather in a payload in the body of the request. Second The Box API Docs & Oauth Tutorial page reference two endpoints. The correct endpoint for the request on the API docs: https://api.box.com/o

Categories : Ruby On Rails

undefined method `total_pages' error in rails4
So you have to define authorization manually for your index action. load_and_authorize_resource skip_load_and_authorize_resource :only => [:getProjectId, :getResult, :index] def index @projects = Project.find_by_sql("SELECT project_id, project_name FROM projects WHERE company_id = "+ current_dashboard_user.company_id.to_s + " ORDER BY project_

Categories : Ruby On Rails

Am not able to run rails server
Mavericks comes with ruby 2 preinstalled. Though you might tune the installation and install missing ruby-dev, I would highly recommend you to install ruby via rvm (preferred) or rbenv so you can manage multiple ruby versions and use gemsets. Here is a good step-through explanation on how to do this.

Categories : Ruby On Rails

A more efficient way to merge multiple objects together
It's difficult to determine why you're actually lumping everything into a single object. What are you intending to do with the result? If this is just for display purposes, you can use something much simpler and more elegant. Assumptions Models class User < ActiveRecord::Base has_many :players has_many :teams, through: :players end class Player < ActiveRecord::Base belongs_to :user

Categories : Ruby On Rails

Getting database-driven from questions from one model and saving answers to another
I would instead model it as: # column :label, TEXT - the text body of the question # column :input_type, VARCHAR - maps to html input types # ... class Question has_many :answers # since there may be several acceptable answers or options end # column :is_correct, BOOL # column :text, TEXT class Answer belongs_to :question end # Or test class Test has_many :questions has_many :

Categories : Ruby On Rails

authorise view user to not access some pages in rails4 app by using cancancan
Okey, just do this trick for now. Somehow the current_user helper method is being called. So the quickest solution would be if you can do the following. In your application_controller.rb file put this block: def current_user current_dashboard_user end # method_alias :current_user=, current_user # you may need this line if required. helper_method: :current_user I hope this will

Categories : Ruby On Rails

Angular $http request not returning Rails resource
The data you are looking for will be passed as a parameter to the success callback from $http. $scope.posts in your example is the entire http object. Try something like this: angular.module('AngularRails').controller('PostsController', function($scope, $http) { $http.get('/posts.json').success(function(postData, status, headers, config){ $scope.posts = postData; // this is the JSON f

Categories : Ruby On Rails

undefined method `stripe_customer_id=' for #
For this problem I have to use the follow solution it's working I have to create a stripe.rb file in model require "stripe" Stripe.api_key = "xxxxxxxxxx" STRIPE_PUBLIC_KEY = "xxxxxxxxxxxxx" thanks

Categories : Ruby On Rails

undefined local variable or method `user' omniauth callbacks controller
The problem is in the password_required? which is called when the user is saved. def password_required? super && user.blank? end Its trying to test whether the user is blank? However the user variable/method does not exist in its scope. Instead you need to use self which refers to the current instance of User. So the line should be: super && self.blank? or just: super &a

Categories : Ruby On Rails

Rails: How do I check my model objects for validation errors?
@user.errors should return ActiveModel::Errors even when it has no errors. If you want to call method on something that could be an object or nil, you can use try method. http://apidock.com/rails/Object/try

Categories : Ruby On Rails

Rails deeply nested resources alternative to accessing params
You shouldn't need to directly access the params to create your nested records. For example, if in your event#new action, you may have something like @event = Event.new 3.times do question = @event.questions.build 5.times do question.answers.build end end This will create a new Event and take you to the New page. Within your New page, you should have nested fields to create and updat

Categories : Ruby On Rails

Rails app connected to empty db?
I have a feeling your environment variables (ENV['DB_DEV_DATABASE']) are not properly set. You can either set them as per your shell environment (bash, zsh, etc.). For example, if you're working within a bash environment, you would need to add the following into your ~/.bashrc file. export DB_DEV_DATABASE="yourapp_development" # etc. Or you can forego the environment variables and set the value

Categories : Ruby On Rails

Using Wicked with Devise
I assume what you want to do is: after a user fills out the sign up form (a user record is not yet created in this step), the user is redirected to a page where she confirms her password one more time before her user account is created. When you submit your signup form to registration_path(resource_name), devise will create a new user record and log you in. The place where you should submit all u

Categories : Ruby On Rails

ActiveRecord: How can I get all of a user's cars without including those that have not been saved?
You want ActiveRecord's new_record? method and its little friend persisted?.

Categories : Ruby On Rails

If a user has_many cars, and a car has_many appointments, how can I get all of a users appointments?
Have a look at the has_many :through assocation in ActiveRecord. class User < ActiveRecord::Base #... has_many :cars has_many :appointments, through: :cars end The you can get all the appointments for a user with: @user.appointments This will automatically build the INNER JOIN SQL needed to link the appointments to users via the cars table.

Categories : Ruby On Rails

Check for Rails in gem initialization
I would go with: if defined?(Rails) ... end Find the documentation for defined? here: http://ruby-doc.org/docs/keywords/1.9/Object.html#method-i-defined-3F

Categories : Ruby On Rails

Neo4j gem - Query for specific relationships
What you're doing is fine, pluck(:rel) will always return an array. If you know you only want one rel, just do event_rel = current_user.events(:e, :rel).where(id: event_id).limit(1).pluck(:rel).first If you're using the master branch from github, you can use first_rel_to method, which (along with match_to) is changing the way I'm using the gem lately. event_rel = current_user.events.first_rel_

Categories : Ruby On Rails

image_tag not showing paperclip uploaded image
Looks like your issue is related to a recent commit which doesn't properly escape the timestamp. A temporary workaround is to disable the timestamp while a fix is worked-out. For individual calls @company.avatar.url(:thumb, timestamp:false) Or you can disable this globally but putting the following line within your config/initializers/paperclip.rb file. Paperclip::Attachment.default_options[:

Categories : Ruby On Rails

Rails update a field without form
I would do that with ajax: You need something like that in your routes.rb file. resources :orders orders/show.html.erb: <div id="order" data-order-id="<%= @order.id %>"></div> <p id="notice"><%= notice %></p> <p> <strong>Status:</strong> <%= @order.status %> </p> <p> <strong>Name:</strong> <%= @

Categories : Ruby On Rails

Can't add class to Rails link_to
As per the API docs: Be careful when using the older argument style, as an extra literal hash is needed So, the solution was <%= link_to "Individual Images", { action: 'feature_highlights', site_title: site.title }, class: "btn" %>

Categories : Ruby On Rails

In a Ruby Rails App, I am getting "project/app/controllers/workouts_controller.rb:43: syntax error, unexpected keyword_end, expecting $end
Replace Class WorkoutsController < ApplicationController with class WorkoutsController < ApplicationController Same for your model. class keyword should be used in lower register. I assume you misprinted it, thats why parser sees extra end keyword

Categories : Ruby On Rails

Paperclip says content type is wrong when using an external URL as attachment
Hi I don't know whether you found a workaround yet. I have used the following code (amended for your example) to stop Paperclip (4.2.1) raising an exception when a webserver returns an incorrect content-type: def featured_image_from_url(url) self.featured_image = URI.parse(url) # deal with the case where the webserver # returns an incorrect content-type adapter = Paperclip.io_adapters.for

Categories : Ruby On Rails

Getting Capybara::DriverNotFoundError when trying to run Cucumber tests
You mentioned that you edited many files. Could it be that you didn't revert all the changes you made? I think Capybara would pick the 'rack_test' driver by default, and your system could not find the 'rack' driver. Since you're doing Cucumber testing, you must have a file called 'env.rb' under the features/support folder. Make sure you don't force 'rack' as your Capybara driver, and your tests s

Categories : Ruby On Rails

Can't build has_many association with Factory Girl
I had a similar problem, and all according to all the docs I was reading, it should have been working. Here is what finally worked (adapted for your code): change build_list(:post, evaluator.posts_count, user: user) to user.posts = build_list(:post, evaluator.posts_count, user: user) Let me know if that doesn't work, but that's what solved it for me.

Categories : Ruby On Rails

Access hash by primary key - ruby rails
The better way to use arel gem, and to select all record with specific ids is this: ids = params[:player_types].map {|v| v[:id] } @player_types.where(@player_types.class.arel_table[:id].in(ids))

Categories : Ruby On Rails

Understanding Rails Model Associations
Rails Guides provides an explanation as to why you're experiencing the problem. Essentially, when you declare a belongs_to relationship, the foreign key appears on the table for the class declaring it. When you declare a has_one relationship, the foreign key is on the table for the class in the declaration. Example In this scenario, the pictures table would require a page_id foreign key. class

Categories : Ruby On Rails

ActiveRecord SUM of distinct records that have a child matching a condition
In RoR you can do stages.includes(:tasks) .where(training_tasks: {is_complete:false}) .distinct.pluck(:days_to_complete).sum or stages.includes(:tasks) .where(training_tasks: {is_complete:false}) .distinct.to_a.sum(&:days_to_complete)

Categories : Ruby On Rails


Recently Add
Why isn't the confirm box working?
Polymorphic models (not associations!) in Rails
Link_to :Action won't call Controller Method -- Rails 4
Missing template when rendering a collection using local variables
rails simple_form using virtual attributes
uninitialized constant ActiveSupport::TestCase
Rails 4, Paperclip, S3 wrong url path
Neo4j gem - Updating relationship properties method
Error trying to deploy Rails app to Heroku
Modyfying before_action
CarrierWave TypeError (can't dump File) on Heroku
CanCan Ability in Rails - Giving partial manage
Uploading two images using s3 and paperclip on rails app
How to pass hash values of ActiveRecord::Base class
Ruby on rails. Heroku compile assets timeout when i add unicorn gem
Rails Template is Missing Error
Time.now.to_i different on heroku and locally
Simple rails app on Puma throws segfault, cannot handle concurrency
Setting Up Rails to Receive HTTP POST Request
Rails: Is it safe to use params[:bar] in link_to helper?
How to add aggregated columns from SQL SELECT to AR object in Rails
Circular Dependency Error autoloading constant
Groups and Users has many oder has many through?
Rails format specifier differences
Capistrano can not create symlinks: file exist
Admin can't delete users. Ruby on Rails 3 - Michael Hartl
Don't show user name who create post
Using Wicked with Devise (2 step signup process)
RubyOnRails Rake test failures
Rails session start event handler
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.