FAQ Database Discussion Community


nested form, empty symbol for has_many relationship

ruby-on-rails-3.2,nested-forms
So, after I have migrated our application from rails 2 to 3.2, I’ve implemented a nested form for a new class, which has worked perfectly. Unfortunately, I cannot get the same to work with a migrated class and it's keeping me on the edge for days now. Parent model: class...

Add Badges with Item Count to my Navbar using Rails 3.2

ruby-on-rails,twitter-bootstrap,ruby-on-rails-3.2
I am looking for guidance/examples on the best way to add a badge to my <ul class = "nav navbar-nav"> I would like this badge to display the Item Count for all of the projects on the page. views/projects/index.html.erb <& @projects.each do | project | %> views/layouts/_header.html.erb <nav class="navbar navbar-inverse...

how to render a facebook page in view in rails

ruby-on-rails,ruby-on-rails-4,ruby-on-rails-3.2,ruby-on-rails-3.1
Is there any process in rails that i can initialize a remote site web page on my local app page. I want to fetch a remote web page like google home page https://www.google.com through <% render "https://www.google.co.in" %> This is a requirement only because when ever i render a page...

Web hosting of any RoR project [closed]

ruby,ruby-on-rails-3.2
i want to host one of my project which is made in RoR. I need if there are some free web hosting site available.Please provide me some steps how to host one RoR project with its database in web server.

Avoid rollback when rails saves nested_attributes

ruby-on-rails-3.2
Model Overalltransaction accepts_nested_attributes_for :transactions Overalltransaction::Transaction.class_eval do attr_accessible :product_id, :rate, [...], :transaction_attributes end Update Evaluation of nested attributes added to model The create action controller for an overalltransaction, @overalltransaction = Overalltransaction.new(params[:overalltransaction]) @transaction_count = params[:product_ids].count @overalltransaction.transactions.build @transactions = session[:product_ids].map do |product_id| transaction =...

bootstrap datepicker calendar is not coming in Rails 3

ruby,datepicker,ruby-on-rails-3.2
I have included the bootstrap datepicker in my Rails app.But it is not showing anything.Please check my following code. Gemfile: source 'https://rubygems.org' gem 'rails', '3.2.19' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'mysql' # Gems used only for assets and not required # in production...

Rails log show redirect but view remain same

ruby-on-rails,redirect,ruby-on-rails-3.2
I am using rails 3.2.21. I want to redirect a request after creating new element on specific condition. my controller create action code : def create @community_group = Community::Group.new(params[:community_group]) @community_group.member_ids = [] @community_group.member_ids = params[:member_ids].present? ? [@current_user.id] + params[:member_ids] : [@current_user.id] respond_to do |format| if @community_group.save format.html{ redirect_to community_group_path(@community_group) }...

getting wrong number argument error using Rails

ruby,ruby-on-rails-3.2,pdfkit
Hi i am getting the following errors while using wicked_pdf gem in Rails3. error: ArgumentError in UsersController#download_pdf wrong number of arguments (0 for 1) Rails.root: C:/Site/generate4 Application Trace | Framework Trace | Full Trace app/controllers/users_controller.rb:6:in `download_pdf' After clicking on download pdf link the following error is coming. error-2: RuntimeError in...

Load associations to one level while conditionally sideloading associations in Active model serializers

ruby-on-rails-3,ruby-on-rails-3.2,active-model-serializers
AMS version 0.8.3, I created a base_serializer.rb like this and extended the same. class BaseSerializer < ActiveModel::Serializer def include_associations! if @options[:embed] embed = @options[:embed].split(',').map{|item| item.strip.to_sym} embed.each do |assoc| include! assoc if _associations.keys.include?(assoc) end end end end class EventSerializer < BaseSerializer attributes :id, :name has_many :organizers, serializer: OrganizerSerializer has_many :participants, serializer:...

Validation error messages are not displaying in Rails 3

ruby,ruby-on-rails-3.2
I have one issue with rails validation.I have validated all fields in model file but when i am putting some wrong data no error message is displaying.As my form contains Rails's ajax call also i am getting the all field value in rendered html page.check my code below. vendor_add.html.erb: <%=...

The proper search result is not coming using Rails 3

ruby,ruby-on-rails-3.2
I need to access all values from Database according to id but i am getting the following output. Output: all details are #<PaymentVendor:0x1ee5860> all details are #<PaymentVendor:0x1f02798> I am explaining my code below. @rest_ids=[21,22,23] @rest_ids.each do |ids| @pdf_vendor_details = PaymentVendor.where(:id => ids ) puts "all details are #{@pdf_vendor_details}" end From...

Ruby-Reading a specific bash-script file from ruby file

ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-3.2,ruby-on-rails-3.1
#practice.rb $TENANT=gets.chomp('/\p{Alnum}/') $first = $TENANT.slice(0,1).capitalize $second = $TENANT.slice(1..-1) EXPORT_PASSWORD="Export-"+ $first + $second.chomp + "!" EXPORT_FILENAME=$TENANT.chomp + ".xar" file = File.open("/Users/..../input/exporttenant.rb", "r") contents = file.read puts content output = File.open(/.../input/$TENANT.txt, "w") $TENANT=tenant_name file = File.open("/data/workday/wmu/input/exportTenant.properties", "r") $line = file.readlines.select{|line| line.match('DS_ENTRY_OMS_SERVER')} file.close...

Apply an 'or' to an inner joined where clause ActiveRecord

ruby-on-rails,ruby-on-rails-3,activerecord,ruby-on-rails-3.2,rails-activerecord
Model: class QueueList < ActiveRecord::Base has_many :times self.today joins(:times).where(times: { period_type: 'on', date: Date.today} || times: { period_type: 'from', date: Date.today }) end end The above model contains a list of times. Because :times can be in two different period_types, I have to apply an "OR" to this query. Is...

Generate join table records if non yet created before view presentation

ruby,ruby-on-rails-3.2
The Product model needs to update its data via a nested form with various data for its join table Product has_many :productunits, dependent: :destroy has_many :units, through: :productunits Unit has_many :productunits, dependent: :destroy has_many :products, through: :productunits When invoking @productunits = Productunit.where(['product_id = ?', params[:id]]).all only existing productunits are shown....

Redirect to same page after click in edit button using Rails 3

ruby,ajax,ruby-on-rails-3.2
I have a form,when user will submit the form all the submitted data are appearing in a table below the form.In this table there is a edit option .I want when user will click on that edit option again that form will appear with the all table data for user...

Ruby on Rails tags vs HTML tags

ruby-on-rails,ruby-on-rails-3,ruby-on-rails-4,ruby-on-rails-3.2
I have a question about tags in .html.erb files. Which practice is better: Ruby on Rails tags or HTML tags? Is it better to use Ruby on Rails tags as much as possible? Or maybe I should avoid them and choose HTML ones instead? How to decide?...

Rails Association Guidance [on hold]

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...

assigning parent_id from an existing attribute

ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-4,ruby-on-rails-3.2
I have a database that is imported from a CSV file and I would like to assign hierarchy based on the assembly level below. not sure which approach to take. I can write if statements but it will be very long. sorry I am new to this, and I don't...

summaries of rails log with lograge gem

ruby-on-rails,ruby,logging,ruby-on-rails-3.2,logstash
I'm using ELK stack, and I need publish my rails log to logstash server. I'm found some gem to do it, for example: lograge to summarize rails log But when I use lograge, the log result it's: full log + summarize log like: Connecting to database specified by database.yml Connecting...

How to get array element in Rails 3

ruby-on-rails,ruby,ruby-on-rails-3.2
I have a array like this [["SWD", "150325006"], ["GOODS", "150325006"]] in rails 3.I want to get those numbers whose type is "SWD".Please check my code below. payment_controller.rb class PaymentsController < ApplicationController def payment @payment=Vendor.new respond_to do |format| format.html format.js end end def check_type if params[:commit]=="submit" @vendor_type = PaymentVendor.where(:v_name => params[:v_name]).map{|v|[v.v_catagory...

rbenv-capistrano install ruby version 1.9.3p392 instead of 1.9.3p448

ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-3.2
[email protected]:~/Desktop/myproject$ ruby -v ruby 1.9.3p448 (2013-06-27 revision 41675) [i686-linux] However when I run cap deploy:setup install in my production server ruby version 1.9.3p392 My .ruby-version file: 1.9.3-p448 my capistrano-rbenv version is (1.0.5)...

cocoon with devise not working Nested Form

ruby-on-rails,ruby-on-rails-4,devise,ruby-on-rails-3.2,cocoon-gem
i have a new problem, attempt to implement devise with cocoon and its not save in DB. PLEASE HELP ME !!! :D User Model: class User < ActiveRecord::Base has_many :telefonos accepts_nested_attributes_for :telefonos, :reject_if => :all_blank, :allow_destroy => true devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable telefono model: class Telefono <...

Friendly id in nested model

ruby-on-rails,ruby-on-rails-3,ruby-on-rails-3.2,friendly-id
I'm using friendly_id to generate URLs on my rails application. I have to following model organization : Ad : class Ad < ActiveRecord::Base belongs_to :area ... Area : class Area < ActiveRecord::Base has_many :ads validates :name ... And the following function in Ad model to generate the URL for each...

Create a subclass from parent class with relationships with an sti

ruby-on-rails,ruby-on-rails-3.2,subclass,sti
I would like to be able to create a Professor that inherits from User on the same form by selecting the correct role and according to this role be able to link and create the Professor relationships. So I did: User.rb class User < ActiveRecord::Base attr_accessible :institution_id, :email, :password, :password_confirmation,...

who changed the value of “params[:tab]”?

ruby-on-rails,ruby-on-rails-3.2,bootstrap
In one erb file called x.html.erb, I am confused by the following little snippet code: <% params[:tab] |= "Excursion" %> <% availableModels.each do |modelName| %> <% if modelName == "Excursion" %> <li class="<%= params[:tab]=='excursions' ? 'active':''%>"> <a id="excursions_tab" href="#tabExcursions" data-toggle="tab"> Excursions </a> </li> <% elsif modelName == "Workshop" %> <li...

Why does my rails app raise a “database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)” error?

ruby-on-rails-3.2,pg
I just updated my production rails app with Capistrano within a new gemset for ruby 2.2 and I got the following error : /var/www/odpf/shared/bundle/ruby/2.2.0/gems/activerecord-3.2.21/lib/active_record/connection_adapters/abstract/connection_specification.rb:47:in `resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified) This is my database.yml : production: host: localhost port: xxxx adapter: postgresql encoding: utf8 database: odpf pool: 5...

How do I get ActionMailer to log sent messages but NOT include the attachments?

ruby-on-rails,logging,ruby-on-rails-3.2,actionmailer
I like that Rails automatically logs all messages that are sent out from the app. What I don't like is how it fills up my log file with huge blocks of useless Base64-encoded text. This makes looking through the log file a pain because I have to skip past these...

Getting undefined local variable or method error using Rails 3

ruby,ruby-on-rails-3.2
Hi i am getting the following error when trying to render a table using Rails 3. Error: ActionView::Template::Error (undefined local variable or method `result' for #<# <Class:0x3460410>:0x2af4d10>): I am explaining my code snippets below. payments_controller.rb: class PaymentsController < ApplicationController def payment @payment=Vendor.new respond_to do |format| format.html format.js end end def...

Referencing image asset as in-line CSS

ruby-on-rails-3.2,asset-pipeline,carrierwave
Calling an image as a background for a div dynamically, based on a stored image via the asset pipeline. Using carrierwave, the call would be <div class="row imaged-background" style="background:<%= image-url(@staticpage.image_url.to_s) %>"> However, this results in: undefined local variable or method `image Taking out <%= simply results in background: image-url(@staticpage.image_url.to_s)...

Fetching array of data from DB using Rails 3

ruby,ruby-on-rails-3.2
I want to access multiple columns using Rails 3.But it gave me the following error. Error: ArgumentError (wrong number of arguments (2 for 1)): app/controllers/payments_controller.rb:13:in `check_type' Check my below code. payment_controller.rb: class PaymentsController < ApplicationController def payment @payment=Vendor.new respond_to do |format| format.html format.js end end def check_type if params[:commit]=="submit" @vendor_type=PaymentVendor.where(:v_name...

Cannot retrieve a column data using Rails 3

ruby,ruby-on-rails-3.2
I want to access a column of data using Rails 3 but unable to retrieve it.Finally an empty array is coming while rendering the out put table.Please check my table first which is given below. table- Payment_vendors: id Receipt_No type v_amount v_date c_date v_name v_status 7 150325006 SWD 60.00 2015-04-15...

Error when adding a column with several options

ruby-on-rails,ruby-on-rails-3.2,rails-activerecord
I have the following migration in the system I'm working on: class CreateEstoqueGruposProdutos < ActiveRecord::Migration def change create_table :est_grupos_produtos do |t| t.integer :grupos_produtos_nivel_id, :null => false, foreign_key: { references: :est_grupos_produtos_niveis, on_update: :cascade, on_delete: :restrict }, index: { with: [:id], unique: true, :name => 'unique_grupos_produtos_id_nivel' } t.timestamps end end end It...

Generate and download Pdf file using Rails 3

ruby,pdf,ruby-on-rails-3.2,prawn
I have a problem in my code.I need when user will click on download link provided on index page the PDF file will generate and at the same time it will download using Rails 3.I am using prawn gem for generating the PDF.but i can not know what should be...

How to run a delayed_job?

ruby-on-rails-3.2,delayed-job
I am trying to run a job in delayed_jobs .I used the syntax "Mailer.delay.somefunction()".It is present in the delayed_jobs table in the database but doesnt execute.How can i make it run or why it is not running?

DateTime substitution from a string in Ruby/Rails

ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-4,ruby-on-rails-3.2
Imagine that I have this string coming from some external api. The string format is always same including the HTML tags and everything. "<p>The update time is <strong>Tuesday 04/28/15 08:30 AM PDT</strong>, please disregard the old timing.</p>" How do I extract the DateTime from the string (Tuesday 04/28/15 08:30 AM...

application.css changed path when upgrading Rails 3.2.17 to Rails 4.0.0

ruby-on-rails-4,ruby-on-rails-3.2
I am upgrading Rails 3.2.17 to Rails 4.0.0 and my app cannot retrieve it's assets anymore. If I access the page source I can see that the app is trying to load the css from: /stylesheets/jackapp/application.css?body=1 If I delete 'stylesheets' and I see the stylesheet at the following: /jackapp/application.css?body=1 Same...

Display notification if search is not found using Rails 3

ruby,ruby-on-rails-3.2
I am using will_paginate gem for searching data from table as per two date.Here my requirement is If no search data is found there should be one notification to user i.e-"No record found in between these two date.".Mu code files are given below. view_report.html.erb: <div class="col-md-4 col-md-offset-1"> <div class="text-left"> To...

Getting row value from DB by matching two column using Rails 3

sql,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-3.2
I have a table like below structure. table name users id Receipt_No type v_amount v_date c_date v_name v_status 7 150325006 SWD 60.00 2015-04-15 2015-04-28 Deepak No 8 150325006 GOODS 1195.00 2015-04-15 2015-04-28 Deepak No 9 150325006 BURNING 290.00 2015-04-15 2015-04-28 Deep No 10 150325006 BURNING 290.00 2015-04-15 2015-04-15 Deep No...

Getting build task error while running rake db:migrate in rails 3

ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-3.2
I am getting the following error while running command rake db:migrate VERSION=201504******. Error: rake aborted! Don't know how to build task '20150419131135' Actually i have a migration file already.Now i am connecting to a new database .Here i want to create table in that DB.Please check my below file. 20150419131135_create_users.rb:...

convert embedded ruby file to PDF file instead of only HTML file using Rails 3

ruby,ruby-on-rails-3.2,pdfkit
I want to convert my embedded ruby file to PDF file after clicking on a link using Rails 3.I became able to convert simple html file to PDF file using pdfkit gem.I am explaining my code below. users_controller.rb: class UsersController < ApplicationController def index end def download_pdf #html = render_to_string(:action...

Passing two query string parameter using Rails 3

ruby,ruby-on-rails-3.2
I want to pass two id in link_to tag so that by using two id I can fetch data from DB.but in my case it is showing one id is coming with URL in address bar therefore i am getting the following error. Error: ActiveRecord::RecordNotFound in PaymentsController#download_pdf Couldn't find PaymentVendor...

dependant: :destroy leading to postgresql error

ruby-on-rails-3.2,postgresql-9.3
class Accdist < ActiveRecord::Base has_many :accdistlavoraziones, dependent: :destroy When deleting an accdist, the following is being output by the console: Accdist Load (27.3ms) SELECT "accdists".* FROM "accdists" WHERE "accdists"."id" = $1 LIMIT 1 [["id", "1"]] Accdistlavorazione Load (20.2ms) SELECT "accdistlavoraziones".* FROM "accdistlavoraziones" WHERE "accdistlavoraziones"."accdist_id" = 1 SQL (59.7ms) DELETE FROM...

get company description in Ruby

ruby-on-rails,ruby,database,ruby-on-rails-3.2,scaffold
I have a table Company with companyid and companyname, and a table Config for my company configuration that have id, companyid, companyname, config that is in my dropdown generate by rails g scaffold how can I override/change Ruby's Save/create button on creating my new config? Is it right to have...

To generate one for the first time: rails generate symmetric_encryption:config, getting warning, how to fix?

ruby-on-rails,ruby,ruby-on-rails-4,ruby-on-rails-3.2,rubygems
When i starting rails application i'm getting warning like this Symmetric Encryption config not found. To generate one for the first time: rails generate symmetric_encryption:config I don't know, Why its showing if i generate symmetric_encryption:config nothing happened. What is the use of 'symmetric_encryption:config' Where it will use? What it will...

How to automatically call a (browser) Client from a Twilio Conference Call?

ruby,ruby-on-rails-3.2,twilio
Here is the scenario: Assume we have a client with a capability to allow incoming calls, named "Roger". James calls our Twilio number conferenceName = "conftest" caller_id = "+15555555555" response = Twilio::TwiML::Response.new do |r| r.Dial :callerId => caller_id do |d| d.Client 'Roger' end end Now we want Roger to get...