Questions tagged [ruby-on-rails-3]

21869 questions
1

votes
1

answer
1.3k

Views

AbstractController::ActionNotFound error, even though routes.rb is configured

I have a UserController with these methods: class UserController < ApplicationController # snip def test_add_realtime_code end def add_realtime_code if request.post? # snip end end end In my routes.rb, I have this: match '/user/add_realtime_code', :controller => 'user', :action => 'add_realtime_code...
Kevin
1

votes
6

answer
3.6k

Views

Disabled radio button in simple_form with an array

What is the best way to place two radio button inside a simple_form, where one button is by default disabled and another is selected! f.input_field :listing_type, as: :radio_buttons, collection: [ "lease", "sale"], :item_wrapper_class => 'inline' this is giving me two buttons where both are enabled...
geekdeepak
1

votes
2

answer
881

Views

How to optimize/cache Rails query

I've Rails application where query takes way too long time. It uses postgresql DB and query consists of one table with thousands of records. statistics_controller.rb all_data = Usagedata.select([:start_time, :end_time, :node_count, :processors, :id, :wall_duration, :local_user_id]) .where(Usagedata...
Raccoon
1

votes
1

answer
975

Views

How to hide Edit and Delete actions from Show view in ActiveAdmin?

just added Active Admin to my project. I want hide the Edit & Delete action form the Show page, and Edit & Delete action should present in Index page. Is there a better way to do this? Thanks in advance.
Sampat Badhe
1

votes
2

answer
2.9k

Views

Cannot upload file

I have problems to upload a file: Here is my html: 'display:inline; margin-top:-10px' %> 'btn btn-sm btn-info' %> First i tried to simply upload it and to handle it in my controller like this: def import widgets = DBF::Table.new(params[:file], nil, 'cp1252') w = widgets.find(6) p = Patient.new p.vor...
John Smith
1

votes
3

answer
1.1k

Views

How to remove current_user from index of all users?

In otherwords, in my app I have an index that displays the number of total users I'd like to exclude the current_user from this list.. I've used the following code to prevent the user.name and user.profile_photo from showing successfully: However, it still says Showing 2 users when it only shows th...
user3399101
1

votes
2

answer
2.6k

Views

boostrap in a rails application, 404 (Not Found)

I've tried to integrate bootstrap following this procedure found on stackoverflow (my rails version is the 3.2.17, this is a difference), so without a gem but just including the bootstrap files in the relevant project directories. Then i've created an HTML page and i put it in the project public di...
AgostinoX
1

votes
1

answer
2k

Views

How to convert time from UTC to PST in rails

I Ruby on rails application, i am getting time in UTC from database (i.e. in active record object). I want to convert the time to PST before displaying to UI. I tried doing this dataFromDB = DataTable.find_by_sql("select time from datatables"); dataFromDB[0].time = dataFromDB[0].time.in_time_zone("P...
Ajay
1

votes
3

answer
366

Views

CI tool with code metrics for ruby on rails application

I need to integrate a CI(continues integration)+CD(continuous deployment) tool for my ruby on rails application. It would be great if it has the following features. Code metric tool like (metric_fu) Gitlab,Gitlub for repository managements. Following are the list of CI tool I'm consider. https://tra...
1

votes
2

answer
345

Views

Rails where clause for :through association

I have the following associations... class Event < ActiveRecord::Base ... has_many :tags, :through => :taggings This allows me to do something like Event.last.tags and see all tags associated with an email. I'm trying to come up with a where clause for tags where I can do something like... Event.whe...
Mark Locklear
1

votes
2

answer
2.6k

Views

Using after_commit only on create

I have a UserObserver with after_commit (changed from after_create to avoid a race condition error that id not found) to update the count. But I know for every create, update is executing the after_commit code (which I knew would happen). How can I run the after_commit only on create? I have few sol...
Milind
1

votes
2

answer
92

Views

Ruby on Rails. The “view” mode display of the value is without trimming

I have following in the view. The "view" mode display of the value is trimming the leading (and I suppose trailing) spaces from the string. But I don't wont trim value.
David Galstyan
1

votes
3

answer
828

Views

Rails validation / Input check Foreign Character Set

We have a customer that wants to block / detect Non European character sets as Arabian and Chinese. People are now filling in our forms with content like this: I have no clue what the best way to detect Non European character sets. So I am wondering which way to go: some kind of jQuery input validat...
Vinozio
18

votes
5

answer
4.3k

Views

can't activate sqlite3 (~> 1.3.6), already activated sqlite3-1.4.0

I’m using Ubuntu and run into to a problem when using db:migrate for ruby project. rails aborted! LoadError: Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? can't activate sqlite3 (~> 1.3.6), already activated sqlite3-1.4.0. Make sure all dependencies are added to...
Juan Rodriguez
1

votes
1

answer
451

Views

How to save data from Cognito Sync to the server

I have a rails 3.2 server, Android App, our own API and AWS Cognito. Our backend is using PostgreSQL. How do I save the datasets created in cognito sync to our database? Should I listen for the callback of cognito sync's success then save the data using our API? or should I use the aws-sdk at the ra...
tungsten_carbide
1

votes
1

answer
401

Views

How to compare times in different time zones in Ruby?

I have this date that which is in timezone offset format that I need to convert to UTC format. For example: date1 = 2017-07-13T17:13:12-04:00 date2_utc = 2017-07-13 21:13:12 UTC I need to compare if those two date are same date. Or If I can convert date1 to UTC then i can compare those two.
KiranGautam
1

votes
2

answer
1.9k

Views

multiple text fields for a single database entry rails 3

In the app I am building I have a need to combine multiple text fields into a single database column. For example my "Business" entry has a column "Discount" The text field I want to read something like this: % Off . I want both of these to be entered into the database as a string: "10% Off Shoes"...
goddamnyouryan
1

votes
2

answer
2k

Views

environment change in rake task

I am developing Rails v2.3 app with MySQL database and mysql2 gem. I faced a weird situation which is about changing the environment in rake task. (all my setting and configurations for environment and database are correct, no problem for that.) Here is my simple story : I have a rake task like foll...
Mellon
1

votes
1

answer
4k

Views

Rails 3 - undefined method `where' for #<User:0x00000104c69b98>

I have following helper method: def orders_chart_series(orders, start_time) orders_by_day = orders.where(:created_at => start_time.to_date..Date.today). group("date(created_at)"). select("created_at, count(id) as total_price") (start_time.to_date..Date.today).map do |date| order = orders_by_day.dete...
user984621
1

votes
2

answer
375

Views

How can I display the first and last child record for a parent row in Rails 3.1?

I'm rather new to Rails and simply love it's expressive modeling architecture. I'm currently building a routing system with a one to many link between two tables. Consider the following schema: class CreateTrips < ActiveRecord::Migration def self.up create_table :trips do |t| t.string :name end end...
Luc
1

votes
2

answer
1.2k

Views

Rails syntax error assigning a variable with each loop

I'm trying to create a list of recipients to send in an external request by assigning it to a variable by doing the following: recipients = @items.each do |item| {"email"=>"#{Recipient.find_by_id(item.recip_id).email}", "amount"=>"#{item.price}"}, end but I'm getting this error: syntax error, unexpe...
varatis
1

votes
4

answer
3.3k

Views

Not getting the :id of element using AutoComplete jquery

guys I m using the jquery Autocomplete to my rails 3.1 application to getting the countries I want that it should when i type the country initials it gives me the name of country and when i submit my form it sends the :id of that element in params i have done all the things mentions but still not ge...
kunnu
1

votes
1

answer
506

Views

validates_presence_of and unsaved associations

Take the following code (Rails 3.0.10): User < AR has_many :providers Provider < AR belongs_to :user validates_presence_of :user user = User.new user.providers.build # so both models not yet saved but associated with each other user.valid? => false user.errors => {:providers=>["is invalid"]} user.pr...
1

votes
3

answer
4.3k

Views

Why am I getting undefined method `first' for nil:NilClass when trying to pull value from array in ruby on rails?

I created arrays some months back for dealing with the editing of user profile details. When displaying back users registered countries I tap into the array and get the result I want using the stored integers from the db. In my User model I have full list of countries stored in an array: # encoding:...
LondonGuy
1

votes
2

answer
911

Views

Can't save array in Mongoid

I have a has_many relationship with another object. Because of this, Mongoid creates an attribute titled item_ids as an Array so I can conveniently save numerous ids as an array. However, whenever I attempt to save a new array it never actually saves. In my rails console I run the following code. 1....
jason328
1

votes
2

answer
2.5k

Views

Does every belongs_to has_many association need nested routes?

This is a fairly basic question but I haven't been able to find concrete answers online. Every has_many belongs_to does not need nested routes correct? Should you only use nested routes when you're looking for URLs of the form class/:id/class/:id? For example, let's say I have two classes Profile...
Steve
1

votes
1

answer
1.2k

Views

Rails 3.1 and RSS Reader

I want to create a rails 3 app for Reading Rss(Feed). but i could not to find good way in rails 3. this code is working. but i want to read full content of rss. that does not support. require 'rss/2.0' require 'open-uri' result = RSS::Parser.parse(response, false) output += "Feed Title: #{result.cha...
Abolfazl Mahmoodi
1

votes
2

answer
4.1k

Views

Ruby on Rails undefined method user_registration_path

I'm getting an error: NoMethodError in Devise/registrations#new undefined method 'user_registration_path' at this line: resource_name, :url => registration_path(resource_name)) do |f| %> This is my routes: devise_for :user, :controllers => { :registrations => "devise/registrations" }, :skip => [:reg...
hellomello
1

votes
2

answer
2k

Views

Show markers on google maps dynamically -Rails 3.2

i have a working code that shows multiple markers on google map using geocoder such as @nearbys = Place.near("#{params[:address]}", 5,:order => "distance",:units => :km) @nearbys.first(5) and i display the markers using the below code function initialize() { var map; var bounds = new google.maps.La...
Milind
1

votes
3

answer
4.8k

Views

simple form association as hidden field

I'm trying to pass association values as hidden field in simple form so same functionality like when you do ... = simple form for @document do |f| = f.association :clients ...but will generate hidden field insted I'm trying to do it as this = f.association :clients, as: hidden but that wont work o...
equivalent8
1

votes
1

answer
4.6k

Views

jQuery “Object function (e,t){return new v.fn.init(e,t,n)} has no method 'on'”

I'm following @coreyward's example for putting object edit forms in modal dialog windows in Rails, which is outlined in this answer and updated for rails 3.1 in this gist. I'm using Rails 3.2.8 and jQuery-Rails 2.1.3 (jQuery 1.8.2 is what's loading in the app). However, this coffeescript from the gi...
pjmorse
1

votes
1

answer
561

Views

Rails model before_save with MD5 digest

I have a model that some record must be filled automatically after the user input. Then I used before_save callback, but the records will not be stored. This is my model: before_save :create_relation_plus_md5 has_many :bridges attr_accessible :id, :admin_user_id, :md5, :url, :name, :cBox validates_...
damoiser
1

votes
2

answer
503

Views

Using Heroku Postgres database locally in a Rails 3 app

I have downloaded the database from an existing Heroku app onto my local machine. The data I downloaded is in a single file; let's call it herokuapp.db. I also have Postgres installed and I can successfully create a new Postgres database and have my Rails app reference that. What I want to do is mo...
wuliwong
1

votes
2

answer
85

Views

Threshold summing in rails/postgres

I'm making a walkathon rails app. Each walker is sponsored by people who pledge money per lap up to a maximum amount. I have a table called sponsorships that has columns walker_id, amount_per_lap, and max_amount. I want to write a SQL query to determine how much money a walker has raised. There is...
Cyrus
1

votes
2

answer
210

Views

Rails routing misconfiguration

I get the following error No route matches [POST] "/events" with this setup: config/routes.rb namespace :admin do #... resources :events #... end (...)admin/events_controller.rb class Admin::EventsController < Admin::AdminController def index @events = Event.all end def new @event = Event.new end de...
omninonsense
1

votes
3

answer
1k

Views

using .where to test if an attribute is not nil

I am using devise_invitable. I am trying to find all users with invitation_token != nil I thought that User.where(:invitation_token != nil) will do.. but it returns all users.. when I do pry(main)> User.where(:invitation_token != nil)[0].invitation_token User Load (1.0ms) SELECT "users".* FROM "us...
Nick Ginanto
1

votes
2

answer
122

Views

Abbreviating respond_to

I am currently working on a web application built on Rails 3 that heavily uses Ajax/REST for the client side. Thus, I often find myself writing controller actions like this: def create if !params[:name] respond_to do |format| format.html { render json: {}, status: :not_found } format.json { render...
Erik
1

votes
1

answer
748

Views

Jquery-ui datepicker only appears after textbox focused second time

For some reason, when I load the partial and I click the textbox to bring up the datepicker I have to click out of the textbox then click back in the textbox before the datepicker appears. Can anyone see anything wrong or how to fix it so the datepicker appears the first time the textbox is clicked...
rails_developer
1

votes
1

answer
680

Views

How do I make the loop finish when an error is thrown inside?

If I have a loop, and somewhere in the loop, I get an exception or error. How do I keep the loop going? Foos.each do |foo| .... # Random error/exception thrown here .... end Should I have a rescue block in the loop? Will that make the loop finish? Or is there a better alternative?
Christian Fazzini
1

votes
1

answer
1.1k

Views

How do you properly include a conditional css file for IE in Rails 3.1+ (asset pipeline) and haml?

The solutions I've searched online do not work. I currently have rails 3.1 and haml installed. The ie.css file is located under app/assets/stylesheets right next to the application.css. I tried the following but it doesn't work: %html %head = stylesheet_link_tag 'application', :media => 'all' a...
perseverance

View additional questions