FAQ Database Discussion Community
ruby-on-rails,ruby-on-rails-4
I am using rails 4. I have a two models- "Company" & "Employees". Company has_many employees. I want to fetch the company and get all the employees in its nested dictionary in API like this, {"Company":{"name":"companyName", "total_employees":1000000, "Employees":[{"name":"xyz"}, {"name":"abc"}]} In company controller I tried respond_with(Company.for(@current_user.id)) In company model scope :for,...
ruby-on-rails,ruby-on-rails-4,amazon-web-services,passenger,elastic-beanstalk
My Rails 3.2.21 app was running fine on AWS Beanstalk under Passenger Standalone 4.0.53. I migrated the app to Rails 4.2.1 and got it passing all tests on my local development machine (Ubuntu, WEBrick). I deployed it to Beanstalk (aws.push), the deploy succeeds (copied from /ondeck to /current) and: nothing....
ruby-on-rails-4,command-line,console
I'd like to delete records with odd numbered ID's from Hero table using the Rails console. Would someone be so kind as to suggest a way for me to do this? Kind Regards, Ryan...
ruby-on-rails,ruby-on-rails-4,nested-forms
Hi I am using gem "nested_form" and included has_many association in my app sample code is : class Question < ActiveRecord::Base has_many :choices accepts_nested_attributes_for :choices end and in my controller have included this : class QuestionsController < ApplicationController before_action :set_questions, only: [:edit, :update] def edit end def update if @question.update_attributes(question_params)...
ruby-on-rails-4,rails-activerecord,simple-form,omnicontacts-gem
I am using the Omnicontacts Gem to pull a list of contacts. So far that works. I can get the contacts and use them to populate a form so I can pass them to my Contacts Controller to be saved in the Contact Model. I have looked at the Rails...
ruby,ruby-on-rails-4,simple-form
It appears that everything saves properly on my Rails 4 app (using simple_form) when I create a new event, but when I try to update an existing event (by going to events/3/edit), it doesn't save any of the changes. Here is my console log: Started PATCH "/events/3" for 12.43.117.2 at...
ajax,ruby-on-rails-4,submit,reload
I have a partial in my user show page <div id = "AboutMeJS"> <%= render "about_me" %> </div> The _about_me.html.erb partial is: <% unless @user.about.blank? %> <div class = "HeaderRow"> <span class="glyphicon glyphicon-user AboutMe" aria-hidden="true"> </span> <div class = "Header">About <%= about_me_variable %> <% if current_user == @user %> <a...
ruby-on-rails,jquery-ui,ruby-on-rails-4
I'm following Railcasts #147 using Rails 4 instead of 3. The method below is not passing in Rails 4. So far all, all is working except for updating the databse with the new sorted position. Any idea how I can mass update the records? def sort params[:faq].each_with_index do |id, index|...
ruby,ajax,ruby-on-rails-4,devise,warden
Is here any possibility to modify devise SessionsController for ajax communication? Edit I found the solution, and posted it into answers, thanks...
ruby-on-rails,ruby-on-rails-4,rspec,rspec-rails,stub
I'm going to share several pairs of run code and test code. Basically, the test code is only working when I use a find on the object class, but the problem is find is the one method I DON'T want to use because I'm not looking for the primary key!...
ruby-on-rails-3,ruby-on-rails-4,sprockets,tilt
Gem tilt is used with sprockets for Rails assets precompile. We are having hard time to find the version running on our Rails 4 app as tilt --version returns version unknown: $ tilt --version tilt: version unknown tilt --help give no info about how to find version. Is there way...
ruby-on-rails,ruby,ruby-on-rails-4,ruby-on-rails-3.2
I am new to rails 4. I have gone through lots of tutorials and trying to solve below scenario. But still no success. Can anybody point me in the right direction. How to handle associations for below scenario. Scenario: 1. Patient can have many surgeries. 2. Surgery has two types...
ruby-on-rails,ruby-on-rails-4,rails-routing
My app have products, categories and subcategries. I have an admin interface at the url /dash to edit these details. I tried to set the urls like this : Products create, update, destroy and index under the url /dash/products Products show under /products/porduct-code Categories show under /category-name Categories edit list...
ruby-on-rails,ruby-on-rails-4
I have a Result that belongs to a Website. After I create the website I also create the result and redirect to its edit page. Here I want to add some more values. My problem is: When I try to update my Result, then I get: param is missing or...
ruby-on-rails,postgresql,ruby-on-rails-4,search
I have this search method in my user.rb model def self.search(query) where("description like ?", "%#{query}%") end but my search is case sensitive. I want to make it case insensitive. How do I do that? I'm hoping it's a quick fix. Thanks...
ruby-on-rails,ruby-on-rails-4,rspec,controller,rspec-rails
This is my controller: class PlansController def use_new_card @user = User.find_by_id(new_card_params[:user_id]) if new_stripe_card ... end private def new_card_params params.permit(:user_id, :stripeToken) end def new_stripe_card StripeService.new({user_id: @user.id, customer_id: @user.stripe_customer_id, source: new_card_params[:stripeToken]}).new_card end end I'm trying to write a controller spec that tests that when the proper parameters are POST to the use_new_card...
ruby-on-rails-4,devise,devise-invitable
For each User I want to display his invitation status: "Invitation Sent" or "Invitation Accepted" Currently I just check if a field encrypted_password in Users table contains anything. If it is not - then a user did not registered (accepted an invitation) yet but it was sent to him (otherwise...
ruby-on-rails,ruby,ruby-on-rails-4
I'm having difficulty associating a review to the current user. Here are my models: User model: class User < ActiveRecord::Base attr_accessor :password before_save :encrypt_password validates_confirmation_of :password validates_presence_of :password, :on => :create validates_presence_of :email, :first_name validates_uniqueness_of :email def self.authenticate(email, password) user = find_by_email(email) if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt) user...
javascript,mysql,ruby-on-rails,ruby-on-rails-4,private-pub
I am creating a simple chatting app on rails 4. The controllers, models and views are created but the functionality is still incomplete. I have 2 tables in my database, conversations and messages. The conversation table holds two fields, sender id and receiver id. And the messages table holds 3...
ruby-on-rails-4,activerecord,model-view-controller,scope,parent-child
I have a class which belongs to another. course.rb class Course < ActiveRecord::Base belongs_to :school I currently use a before_action to set the parent instance in the controller. courses_controller.rb class CoursesController < ApplicationController #returns @school. only: [methods] avoids trying to set @school when no school param expected before_action :set_school, only:...
ruby-on-rails,ruby-on-rails-3,ruby-on-rails-4,twitter-bootstrap-3,rubygems
I generated views using this command rails g bootstrap:themed Todo it generated several views for my model. I am using git and reverted the project to its former branch without the boostrap. Now, I am trying to regenerate the views but it always returns this identical app/views/manifests/index.html.erb How do I...
ruby-on-rails,ruby,ruby-on-rails-4
I have the following properly working line in a view that adds a class depending on the current_page of the user: <li class="hvr-bottom <%= 'active' if current_page?(root_path) %>"> <%= link_to "Home", root_path %> </li> Now I would also like to add a different class for the else situation, and I...
oop,ruby-on-rails-4
I am a beginner in rails. As I was working on rails validation, I wanted to know where is the definition of valid? and new_record? and all the validation helpers? I was trying to find the definition of all these functions but couldn't find any. Where do all this validations...
ruby-on-rails,ruby-on-rails-4
I want to use acts-as-votable to implement a voting system where I can supply multiple custom options - e.g. 5 buttons ('blue', 'red', 'green', 'grey', 'white'). I want my users to be able to choose only 1 of those colors, but I would like to be able to tally up...
ruby,ruby-on-rails-4,method-overriding
In rails app, how are helpers included in viewcontrollers, and what's the order of includion(which helper is included first, second, so on)? Also, are all helpers available to views? If so, does the inclusion order same as the view's corresponding controller?...
css,ruby-on-rails,ruby-on-rails-4,haml
I'm trying to override my application.css with other css, included in header. I want to customize my application.css by this way. My header = stylesheet_link_tag 'application', media: 'all' = stylesheet_link_tag 'customized_css', media: 'all' Actual application.css.scss is overriding my tour.css.scss even its is loading before any other css Edit The order...
ruby-on-rails-4,capybara
I understand the syntax for Capybara choosing a radio button is the following choose("Label Name") I am running into an issue with doing this for a label that has its default name changed to an #id. Here is my HTML <label for="school_application_I_20"> Do you require an I-20 Form?</label> <br> <label...
ruby-on-rails,postgresql,ruby-on-rails-4,amazon-web-services,heroku
How do I download my dump directly from Amazon AWS S3 if heroku pgbackups:url b004 isn't working? Specifically, when I run this command it returns: ! Please add the pgbackups addon first via: ! heroku addons:add pgbackups And then when I run this command I get: ! No such add-on...
ruby-on-rails,ruby-on-rails-4,model-view-controller
I have two partial views for two different sign up forms. On my home page , based on the link one clicks on, I'm rendering respective form.(views/application/index) = link_to 'Mentor', new_user_path(user_role: true), :class =>'btn' = link_to 'Mentee', new_user_path, :class =>'btn' In views/users/new.html.haml , I'm checking the user role and redirecting...
javascript,html,ruby-on-rails,ruby-on-rails-4,background-image
I am on Rails 4, and finally got this javascript working. It changes randomly changes the background image every 10 seconds with a fadein fadeout effect. The only issue is every so often, an image will only load halfway... then it will start to flash and and get crazy. It...
ruby-on-rails,ruby,ruby-on-rails-4
I have the following line of code: <%= "Brand: " + (@user.activated ? "image_tag('brand1.png', class: 'branding')" : "image_tag('brand2.png', class: 'branding')") + "(#{@user.activated_at})" %> It should show (where the image shown depends on whether user is activated): Brand: {image} 6-19-2015 Instead of the image, it displays the literal image path (so...
ruby-on-rails,ruby-on-rails-4,heroku,dns
App running Ruby 2.2.2, Rails 4.2.1 When I run my app locally everything is fine. It was running fine on heroku until I made some updates. Now all I get in a browser is "Err too many redirects" from Chrome, or "Too many redirects..." in Safari. Even after I rolled...
ruby-on-rails,ruby-on-rails-4
I'm trying to do something that I imagine to be very basic, but I'm very new to Rails and am not sure what sure what I'm doing wrong. I've gone through several tutorials and searched for an answer and can't find what the issue is. Would appreciate any help! I've...
ruby-on-rails,ruby,ruby-on-rails-4
I am having trouble building a controller concern. I would like the concern to extend the classes available actions. Given I have the controller 'SamplesController' class SamplesController < ApplicationController include Searchable perform_search_on(Sample, handle: [ClothingType, Company, Collection, Color]) end I include the module 'Searchable' module Searchable extend ActiveSupport::Concern module ClassMethods def...
ruby,ruby-on-rails-4
I am unsure why i am getting the below error. I am new to rails and any help and advise would be much appreciated. i am creating a recruitment site i am trying to allow jobseekers to upload their profile image which works successfully now, i am trying to allow...
ruby-on-rails,ruby-on-rails-4,devise,bcrypt
I have a custom User model with lots of rows. I have a password_digest column that I want to keep. (it comes from has_secure_password) And I also want to use Devise database authenticatable, but from my limited knowledge on Devise, I have to use the encrypted_password column. Is there a...
ruby-on-rails,ruby-on-rails-4,associations,activemodel
I'm hoping that this question will lead to me understanding more about how to construct many-to-many relationships with foreign keys that don't have inherant "Rails magic", as I've been Googling for hours and still don't fully understand. Basically, Users can organize Events, and Events can be organized by many Users....
ruby-on-rails,ruby,ruby-on-rails-4,acts-as-taggable-on
I am using the gem acts_as_taggable_on. I have it setup and working correctly. I am trying to create a page that lists all the tags with the posts underneath each tag they belong to? (Tag 1) Post tagged with tag 1 Post tagged with tag 1 Post tagged with tag...
ruby-on-rails,ruby,ruby-on-rails-4,mongoid,paperclip
class User include Mongoid::Document has_many :images accepts_nested_attributes_for :image end class Image include Mongoid::Document include Mongoid::Timestamps include Mongoid::Paperclip has_mongoid_attached_file :uploaded_image, :path => ":rails_root/public/uploads/:class/:id/:basename.:extension", :url => "public/uploads/" validates_attachment_content_type :uploaded_file, :content_type => "application/png", :message => "error massage" belongs_to :user delegate :url, :path, to: :uploaded_image, allow_nil: true, prefix: false...
ruby-on-rails,ruby,ruby-on-rails-4
I have standard flash messages throughout my app, using bootstrap for styling. These work fine but I would like to add a functionality. A visitor who gets a flash message on his/her screen, should have the ability to click the flash message away / to make flash message disappear. For...
ruby-on-rails,ruby,ruby-on-rails-4,devise
I am trying to make a "next" button that should generate a Viewed_lesson (user_id, lesson_id, boolean: true) and then redirect to the next lesson. The purpose is to make a tracking progress to show the progress of the user over a course. My models: class Course has_many :lessons end class...
ruby-on-rails-4,heroku,devise,sendgrid
I am using sendgrid to send emails in production my all other emails are being sent as expected but all the devise emails are not being sent neither a crash occur my in my production.rb I have config.action_mailer.raise_delivery_errors = false config.action_mailer.default_url_options = { :host => 'myapp.herokuapp.com' } config.action_mailer.delivery_method = :smtp...
ruby-on-rails,ruby,ruby-on-rails-4
I want to calculate the percentage of body groups for all injuries, but can't figure it out. Injury model: class Injury < ActiveRecord::Base belongs_to :player belongs_to :season has_one :injury_type end InjuryType model: class InjuryType < ActiveRecord::Base has_one :body_group end BodyGroup model (no association): class BodyGroup < ActiveRecord::Base end I print...
ruby-on-rails,ruby,ruby-on-rails-4,models
I've got two tables, User and Allergy. These are connected via another table, UserAllergy. The models are as would be expected: class User has_many :user_allergies has_many :allergies, through: :user_allergies end class UserAllergy belongs_to :user belongs_to :allergy end class Allergy has_many :user_allergies has_many :users, through :user_allergies end What I'm confused about...
sql,ruby-on-rails,ruby,ruby-on-rails-4
I have a model called Issue that has the following database structure : class CreateIssues < ActiveRecord::Migration def change create_table :issues do |t| t.string :path, null: false t.string :filename, null: false t.string :name, null: false t.string :year t.integer :number t.timestamps null: false end end end In my model tests, I...
ruby-on-rails,ruby,ruby-on-rails-4
Knowing that this is possible in Ruby: method_name param, other_method other_param Which would be the equivalent in another programming language to: method_name(param, other_method(other_param)) Why is it that it is not possible to do that with the auto-generated route helpers, which are methods just like the others? For example: <%= link_to...
ruby-on-rails,ruby,ruby-on-rails-4
I just got a new computer at work and I have rails up and running with no problems. But oddly I am missing the useful rails console that pops up whenever you run into an error in Rails. It is usually at the bottom of the page and is black....
javascript,jquery,html,ruby-on-rails,ruby-on-rails-4
Can someone tell me what is wrong in this Javascript ? It's supposed to show an alert "already opened" if there's plus (or) 2 PP div with a class "open". if ($('PP').not('.closed')>=2) { window.alert('already opened'); } ...
ruby-on-rails,ruby-on-rails-4,mongoid,embedded-documents
I'm trying to create a Mongoid N-N reference association between two embedded documents in Rails 4 however I'm finding it difficult to get my head round how this is done. I started by adding the HABTM association to the relevant models below (Track and Option) but of course I'm getting...
ruby,ruby-on-rails-4
I would like to do smth like: a = Hash.new a = {:profile => @user} a[:profile][:contacts] = Hash.new a[:profile][:contacts] = @user.contacts.all but I am getting the error can't write unknown attribute `contacts'. @user is the result of a select from our database. I need to create a hash with this...
ruby-on-rails,ruby-on-rails-4,activerecord,rspec,nested-attributes
I'm new at Rails programming, and my RSpec test is failing when trying to save nested records. The logs from the test suggest that ActiveRecord is trying to save the parent twice, which results in a silent database save failure. sign_up_spec.rb (sorry for the omission!) require 'rails_helper' RSpec.feature "Accounts", type:...
ruby-on-rails,ruby,ruby-on-rails-4,delayed-job,rails-activejob
With delayed_job, I was able to do simple operations like this: @foo.delay.increment!(:myfield) Is it possible to do the same with Rails' new ActiveJob? (without creating a whole bunch of job classes that do these small operations)...
ruby-on-rails,ruby,ruby-on-rails-4,controller
My OrdersController is as follows below, but I keep getting this message: undefined method `listing_id=' for # Extracted source (around line #31): 29 30 31 @order.listing_id = @listing.id Is there something I am doing incorrectly? Am following a tutorial so followed the instructions, then when it wasn't working decided to...
sql,ruby-on-rails,ruby,ruby-on-rails-4,activerecord
Let say I have a Group of Users and User has a enum, which described it's mood. class Group < AR::Base has_many :users class User < AR::Base belongs_to :group enum mood: %i(good bad ugly) How can I find all groups, where at least one User has the good mood? Which...
excel,ruby-on-rails-4,devise
(rails 4, ruby 2.0, excel for osx 14.5, but same problem detected in windows excel) I have a link in excel that looks like: https://www.example.com/reports/download_frame/1481 When the user clicks in excel they get routed to the default home page. When they cut and paste the same url into a browser...
ruby-on-rails,ruby-on-rails-4,activeadmin
I am trying to organize my models so that I get to see in lecture.rb > chapter.rb > lesson.rb. As you can imagine chapter.rb have to be organized by order in the view as well as the nested lesson within chapters. It is a bit confusing.. My idea so far...
ruby-on-rails,arrays,ruby,loops,ruby-on-rails-4
I'm running into several syntax and nil issues when trying to create this hash idea_benefit_count. @idea = @domain.ideas @idea_evaluations = Array.new() @idea.each do |idea| @idea_evaluations << idea.evaluations end @idea_benefit = [] if [email protected]_evaluations.nil? @idea_evaluations.each do |eval| @idea_benefit << eval.benefit end @idea_benefit_count = Hash.new(0) @idea_benefit.flatten.each { |idea_benefit| @idea_benefit_count[idea_benefit] += 1 }...
jquery,ruby-on-rails,ruby-on-rails-4,pickadate
I am working with pickadate in Application. Here I store holidays dynamically in database. I am fetching that dates with gem 'gon'. gon.holidays = @holidays.collect { |holiday| [holiday.date] } in application.js alert(gon.holidays); output is To disable dates in pickadate. I followed $( '.new_leave_datepicker' ).pickadate({ selectMonths: true, selectYears: 25, disable: [...
ruby-on-rails,ruby,ruby-on-rails-4
I am unsure why i get the below error. I am new to rails so Any help and explanation will be much appreciated. i am trying to send emails to subscribers each time a blog is created. in my blog controller i have added after_create :send_email_to_subscribers in my blog controller...
ruby-on-rails,ruby-on-rails-4,rspec,rspec-rails,stub
This might sound like a terribly basic question... so let me explain the context. I'm retrieving an event from Stripe, but for the purposes of this, but this works for other things that I've considered. The data that I need in the Stripe object is way buried, so I'd have...
ruby-on-rails,ruby,postgresql,ruby-on-rails-4,activerecord
Each question has an array of tags. schema.rb: create_table "questions", force: true do |t| t.text "tags", default: [], array: true How to atomically append to tags? How to prevent dups within the array? I tried question.update_attribute tags: tags << :ruby, but this doesn't work. Rails 4.17 and Postgres. EDIT: This...
ruby,ruby-on-rails-4
I have an array filled with Datetime objects: [Mon, 22 Jun 2015, Tue, 23 Jun 2015, Wed, 24 Jun 2015, Thu, 25 Jun 2015, Fri, 26 Jun 2015, Sat, 27 Jun 2015, Sun, 28 Jun 2015] I know how to select what I want from the array ex: week.select{|x|x.monday? ||...
ruby-on-rails,json,ruby-on-rails-4,sidekiq
I have a small To Do list in a .json file that I´m reading, parsing, and saving to a rails app with Sidekiq. Everytime I refresh the browser, the worker executes and duplicates the entries on the database. How do I maintain a unique database that is synchronized with the...
ruby-on-rails,ruby,ruby-on-rails-4,activerecord
In Rails, ActiveRecord objects, attributes are accessible via method as well as through Hash. Example: user = User.first # Assuming User to be inheriting from ActiveRecord::Base user.name # Accessing attribute 'name' via method user[:name] # Attribute 'name' is accessible via hash as well How to make instance variables accessible through...
ruby-on-rails,ruby-on-rails-4,internationalization,rails-i18n
I'm trying to translate a month with I18n and I'm getting this error: undefined method `strftime' for "2015-05-18":String Code: # controller @previous_month = I18n.l(Date.today - (1%12).months) # view @previous_month.strftime('%B') How can I solve this error?...
ruby-on-rails,ruby,validation,ruby-on-rails-4,associations
An Organization model has a 1:many association with a User model. I have the following validation in my User model file: belongs_to :organization validates_presence_of :organization_id, :unless => 'usertype==1' If usertype is 1, it means the user will have no organization associated to it. For a different usertype the presence of...
ruby-on-rails-4,imagemagick,paperclip
I am using paperclip gem to process images. In some images, I need to chop the top 35 pixels of the source image and then do the conversions and processing Currently I am using :convert_options => { all: lambda{ |instance| "#{!instance.chop_top.blank? ? '-chop 0x35' : '' } -limit memory 64...
ruby-on-rails,ruby,forms,ruby-on-rails-4,controller
I have a contact form on a special page dedicated to this form. The dedicated controller includes: def new @message = Message.new end def create @message = Message.new(message_params) if @message.valid? MessageMailer.new_message(@message).deliver_now flash[:success] = "Thank you!" redirect_to contact_path else render 'new' end end Now I would also like to include this...
ruby-on-rails-4,routing
This question seems a little basic, but considering I have 'pages#show' with a show page with url 'history'. How could I add this specific show page to a link: = link_to 'History', pages_path(@?????) PD1: I would prefer avoid using :id since I tend to seed a lot of data, and...
ruby-on-rails,ruby-on-rails-4,inflection
I have included inflections.rb ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.irregular 'leaves', 'leaves' end and my controller leaves_controller.rb class LeavesController < ApplicationController def new @leave = Leave.new end def create @leave = Leave.create(leave_params) if @leave.errors.present? render :action => :new else redirect_to root_path, notice: I18n.t('leave_applied') end end private def leave_params params.require(:leave).permit(:start_date,:end_date) end end in...
ruby-on-rails-4,activerecord,associations
I've created a many to many relation ship like the following structure. Class User has_many :companies, :through => company_admins has_many :company_admins end Class Company has_many :company_admins has_many :users, :through => company_admins end Class CompanyAdmin belongs_to :company belongs_to :user end Here, User can be assigned as admin on many Company. Now...
ruby-on-rails,ruby,ruby-on-rails-4,virtual-attribute
I have a model of product and I need to write in the _form view , the number of the product that an admin wants to insert. I have another table with the Supply (number of product) so in my product table I don't have the attribute quantity , but...
angularjs,html5,templates,ruby-on-rails-4,slim
Trying to attach custom angular attribute directive to rails slim template. But all attempts are not successful. Here is the code input#title.form-control placeholder="Product titile" type="text" ng-model='product.title' server-error where 'server-error' is a custom directive. But when browser renders this html this directive is cutted off and printed as a plain text....
ruby,ruby-on-rails-4,elasticsearch
I'm trying to create an elasticsearch query that have the following logic: search by title, and if the type of record is given, also add it to the query. I did this def to_es_query { query: { match: { title_en: { query: @title } }.merge!(optional_params) } } end def optional_params...
sql,ruby-on-rails-4,subquery,select-n-plus-1
A :parent has_many :children and I am trying to retrieve the age of the oldest child for a parent as an attribute on the parent. I'm open to any solution that accomplishes that efficiently. The reason I'm trying to do a subquery is to let the DB do the n+1...
ruby-on-rails,twitter-bootstrap,ruby-on-rails-4,asset-pipeline
I am trying to add background image on my web page, it was working when I was using plane html, but now I am integrating it to my rails application. I am using this code to embed the image in my rails application <div class="jumbotron" style="background-image: "url(image-url('lines3.png')"; background-repeat: repeat-x; background-position:...
ruby-on-rails,ruby-on-rails-4,rspec,devise
I've written some custom code for Devise registration. Namely once a user hits the "sign up" button, Devise's generic code ensures that the user is saved correctly. But then, I want to go in and make sure that the user gets an associated Stripe customer account. Most of the code...
ruby-on-rails,ruby,ruby-on-rails-4,erb,view-helpers
On my view view, I have the following format I want to output: <tr> <th>Released:</th> <td> <%= movie.release_at.to_s(:release_date) %> (<%= time_ago_in_words(movie.release_at) %>) </td> </tr> The exact format I want is "Month Day, Year", so I created an initialize file with the following: Date::DATE_FORMATS[:default] = "%B %e, %Y" My database schema...
ruby-on-rails,ruby-on-rails-3,ruby-on-rails-4
I'm trying to write a simple helper method that checks if a user's email address contains a specific domain name. The method is needed in all my controllers and depends on the state of current_user, so I felt the best place to put it would be in my ApplicationController. Depending...
html,css,ruby-on-rails,ruby-on-rails-4
I'm having problems with styling my navigation bar, specifally the drop-down menu within the navigation bar. The two li elements below (the ones linking to "Profile" and "Edit profile" don't show up right. As you can see I have added the class my-dropdown-item in two different manners, both with the...
jquery,ruby-on-rails,ruby,ruby-on-rails-4,rubygems
I am practicing ruby on rails by using rails guides. In the section 5.13 Deleting Articles they are showing how to create the delete (destroy) functionality. I followed the steps correctly, but the delete confirmation dialogue isn't shown and the articles are not getting deleted. When I checked the chrome...
mysql,ruby-on-rails,ruby,ruby-on-rails-4
Im trying to install an open source rails 3.2.21 application that uses the mysql2 gem, but when i try and run the bundle commant I get the following error: Fetching: mysql2-0.3.18.gem (100%) Building native extensions. This could take a while... p ERROR: Error installing mysql2: ERROR: Failed to build gem...
ruby-on-rails,ruby,ruby-on-rails-4,twitter
I have a model named Tweet. The columns of the Tweet model are: -id -content -user_id -picture -group -original_tweet_id Every tweet can have one or multiple retweets. The relation happens with the help of original_tweet_id. All the tweets have original_tweet_id nil , whilst the retweets contain the id of the...
html,ruby-on-rails,image,ruby-on-rails-4,svg
I am trying to replace the tag with link_to in my rails application view. for replacing I have svg icon, text and link all in one tag. Here is below <a class="navbar-brand" href="index.html"><%= image_tag 'logo.svg', "data-svg-fallback" => image_path('logo.svg'), :align=> "left" ,:style => "padding-right: 5px;" %> My Project </a> but I...
ruby-on-rails,ruby,ruby-on-rails-4,activerecord
I have a form that a user fills out that I need to add some extra 'behind the scenes' data to before creating the object in my DB. For instance, data like a referrer_url, clout_score etc. How do I go about doing it? Are the methods something that should sit...
ruby-on-rails,ruby,ruby-on-rails-4
My rails app gives following error: NameError (undefined local variable or method 'fac_allocs' for #): app/models/room.rb:4:in '' app/models/room.rb:1:in '' app/controllers/rooms_controller.rb:3:in 'index' room.rb file class Room < ActiveRecord::Base has_many :bookings has_many :fac_allocs has_many :facs, :through => fac_allocs end ...
ruby-on-rails,ruby,ruby-on-rails-4
I am using Rails 4.2 and Ruby 2.1.5 Here is my radio button code of my new template: <%= form_for @api, :url => commons_path do |f| %> <div class="form-group"> <%= f.label :status, "Status", class: "col-sm-2 control-label" %> <div class="col-sm-8"> <%= f.radio_button :status, 'success' %> <%= label_tag(:status, "Success") %> <%= f.radio_button...
ruby-on-rails,ruby-on-rails-4,activerecord
My Controller: def index @three_data = Threeddatum.all @three_data = @three_data.search(params[:search]) if params[:search].present? end My model: def self.search(search) if search self.where("area LIKE ?", "%#{:search}%") else self.all end end My view: <%= form_tag('/threeddata', method: :get) do %> <%= text_field_tag :search, params[:search] %> <%= submit_tag "Search", name: nil %> <% end %> <%...
ruby-on-rails-4,session-cookies,form-submit,session-state
I'm using a session to auto fill the first half of a form in Rails 4. The first time a customer submits a form (featuring their details and product details), the customers details are stored into a session. Upon subsequent forms (additional orders), the customer's details are pulled from the...
ruby-on-rails,validation,ruby-on-rails-4
I am using Rails 4.2 with Ruby 2.1.5. Here is my API table: create_table "apis", force: :cascade do |t| t.string "name" t.datetime "created_at" t.datetime "updated_at" t.string "status" t.string "coname" end How do I validate that a user cannot create an API with the same name and same status twice? For...
ruby-on-rails,ruby-on-rails-4
I have two models: User class User < ActiveRecord::Base has_and_belongs_to_many :partners end and Partner class Partner < ActiveRecord::Base has_and_belongs_to_many :users end and now, i want change it to: class User < ActiveRecord::Base has_many :partners end class Partner < ActiveRecord::Base belongs_to :user end but how can i do it by migration?...
ruby-on-rails,ruby-on-rails-4,redirect
I want to create a new record if it not exist. Otherwise, redirect to edit page automatically. In case the record exists (e.g: @sale is not nil). However, I got error message: app/views/sales/_form.html.erb where line #1 raised: First argument in form cannot contain nil or be empty Please show place...
date,ruby-on-rails-4
I have a date_select in my form: <%= f.date_select :birthdate, {:start_year => Time.now.year - 100} %> I have a field t.date "birthdate" How can I save the value selected in date_select to the database (@user.birthdate)? (without using any gems like datepicker)...
ruby,ruby-on-rails-3,ruby-on-rails-4,nested-forms
I have 3 tables: members, meetings, meeting_has_members. The models are: member.rb class Member < ActiveRecord::Base has_many :meeting_has_members has_many :meetings, through: :meeting_has_members accepts_nested_attributes_for :meeting_has_members accepts_nested_attributes_for :meetings meeting.rb class Meeting < ActiveRecord::Base has_many :meeting_has_members has_many :members, through: :meeting_has_members accepts_nested_attributes_for :meeting_has_members accepts_nested_attributes_for :members meeting_has_member.rb class...
ruby-on-rails,ruby-on-rails-4
In my Rails app, each User has many graphs, each Graph has many trackables, and each Trackable has many points (with a value and time). Users are able to add (or remove) different trackables to plot vs created_at time. Users can to go to a graph's show page and submit...
ruby-on-rails-4,activerecord,has-many-through
I am working with has_many :through association in Application. I implement association between models like :- in employee.rb class Employee < ActiveRecord::Base has_many :inventories, through: :employee_inventories end in inventory.rb class Inventory < ActiveRecord::Base has_many :employees, through: :employee_inventories end in employee_inventories.rb class EmployeeInventory < ActiveRecord::Base belongs_to :employee belongs_to :inventory end I...
ruby-on-rails,ruby,ruby-on-rails-4,model-view-controller
I have a navigation bar included in application.html.erb. Because for some pages, such as the signup page, I need to place additional code inside the navigation bar, I have excluded those pages for showing the navigation bar through application.html.erb and instead included it in their respective view pages. See code...
ruby-on-rails,email,ruby-on-rails-4,devise,mailer
Just set up my first mailer on Rails 4. I have a welcome email sent to new users as soon as they sign up (create) for a new account using devise. I also have devise set up so that if a current_user is not found, a guest user will be...
ruby-on-rails-4,wicked-pdf
I'm trying to save pdf on server using rails model buts its generate a blank pdf. Earlier did it in controller without problem but now its creating a blank one. Any idea What's i did wrong? def generate_bulk_pdf view = ActionView::Base.new(ActionController::Base.view_paths, {}) view.extend(ApplicationHelper) view.extend(AbstractController::Rendering) view.extend(Rails.application.routes.url_helpers) students = Student.all.order('id ASC') students.each...
ruby-on-rails-4,amazon-s3
I work on a SaaS application where Creators can create Groups and invite others to their Group to share files, chat and so on. Only people within specific group should have access to this group's files. People from other group must not have access to not their group's files. And...