Questions tagged [ruby]
136894 questions
1
votes
1
answer
530
Views
Twilio: Outputting the SID of a conference
When you dial a phone number through the Twilio API, the platform passes the call's unique 34 character SID to your application as a parameter.
For example, when the Twiml I send to the Twilio platform dials a call through a < Dial > verb, I can easily do:
puts params['CallSid']
@incoming_Cid = par...
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...
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...
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...
1
votes
1
answer
1.6k
Views
Google Calendar API V3 - Insert Calendar
I am playing around with Google calendar API and came across this:
Google Calendar V3 Insert
The Ruby code doesn't seem to be Ruby code so I ported information from the calendar_list and calendar.get to this. I'm not sure why the parameter summary is not being picked up as a title.
def create...
1
votes
1
answer
305
Views
Why does gem not auto compile my C extension
I build a Ruby gem, which needs some C extension. This one - once compiled - is bound via Ruby FFI into the gem.
My setup: I use bundle for the gem scaffolding. Inside my gems folder I have a subfolder ext. This one includes a static Makefile, another subfolder source and an extconf.rb.
The source f...
1
votes
1
answer
431
Views
SQLite and Ruby rescue
I'm following the pretty great SLite & Ruby tutorial over at ZetCode and have run into a silly question. What exactly is going on here?
rescue SQLite3::Exception => e
puts "Exception occured"
puts e
I conceptually get what's happening: if an exception is raised, it gets printed on the screen. But w...
1
votes
2
answer
962
Views
Freezing Rails gem versions
I am trying to freeze my Rails gem version as, day by day, some or the other gem version gets updated and sometimes I need to update the code.
I tried rake rails:freeze:gems but this gave me error:
rake aborted!
Don't know how to build task 'rails:freeze:gems'
1
votes
4
answer
1.1k
Views
Cannot register user Unpermitted parameters error with devise and devise_invitable
I am on Rails3.2 devise_invitable (1.1.8), devise (3.1.1) WITHOUT strong parameter, when I try to register a user I get following log. I am using this route to custom the devise invitation controller:
devise_for :users, path_names: {sign_in: "login", sign_out: "logout"}, :controllers => { :invita...
1
votes
1
answer
1.1k
Views
Example code for “google-search” gem not working?
Every time I run this code (which was given as an example for the "google-search" gem), all three of my rank_for queries are returned as "Not found."
Thinking maybe the problem is in if item = find_item(/vision\-media\.ca/, query) as I'm not sure why they're referring to the vision-media.ca site.
Pl...
1
votes
2
answer
3.5k
Views
Webdriver in Ruby, how to check elements exist
I am using Webdriver in Ruby and I want to verify three text exists on a page.
Here is the piece of html I want to verify:
many subtags
test1
manny other
test2
manny other
test3
manny other >
How do I verify "test1", "test2" and "test3" presents on this page using
find_element
find_elements
getPag...
1
votes
2
answer
1.8k
Views
How can I return a 404 for a specific URL with Rack middleware
A site I manage is getting constant requests for a javascript file that no longer exists, from an older version of the site. These requests take up a lot of resources because they get routed through Rails every time to return a 404. I am thinking it would be much better to have Rack handle that spec...
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.
1
votes
2
answer
584
Views
Using scope in Rails model for gathering “private” posts
I have a table of user Posts, some of which are private, denoted by a boolean column (privacy) in the table (true being private). In my livefeed view (posts/index.html.erb), I want to show only the non-private posts for ALL users. Can I do this via my scope?
Note: In my usersfeed view I am showing p...
1
votes
1
answer
2k
Views
eCommerce solution for ruby on rails with multi-store support [closed]
As i know in rails there is limited support for eCommerce solution(few options):
Spree
Ror-e
Substruct
Piggybak
I didn't use any of this, but wanted to ask that anyone have experience between these solutions, pros&cons. I found similar question: https://stackoverflow.com/questions/9382268/clean-e-co...
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...
1
votes
3
answer
97
Views
How to calculate a formula and get a floating point number
How do I perform some math using this formula? If number is 37, I'd expect it to end up with 133.2.
number / 100 * 360
1
votes
2
answer
912
Views
Conditional Keyword Arguments (Ruby 2.0)
let's say I have this object:
class Post
def initialize(title: 'title', content: 'content')
@title = title
@content = content
end
end
but I would like to add logic like:
class Post
def initialize(title: 'title', content: 'content')
@title = title unless title.empty? # if it's empty I'd like to use t...
1
votes
1
answer
127
Views
Ruby app pushed to Heroku displaying issues
I am running a Ruby on Rails application with a PostgreSQL database. This is the first time I pushed an app with its database to heroku, so I had no idea what to expect. What I got was my main page working as intended; but the Users page (page created by Rails scaffold command wich should display da...
1
votes
2
answer
187
Views
Can I create a new entry in a Rails db by posting XML data in lieu of form data?
I'm playing with a very simple contacts Rails app. I have a /contacts route that I can POST to add entries in the contacts table (using scaffold). I want instead to send XML data in the POST (rather than FORM data) using XMLHttp Request. The request works, but the params object in Rails doesn't show...
1
votes
3
answer
370
Views
Rails: Joining by one table OR another table
I'm looking for a more efficient way to write an ActiveRecord query. I want to get all instances of a model that either join one table or another table. Both is easy, but either is difficult.
Right now, I have the following two queries:
across_clues = Clue.joins(:across_cells)
down_clues = Clue.join...
1
votes
1
answer
1.4k
Views
mailboxer gem - find message sender
I am having the hardest time with the mailboxes gem. I have gotten it working in that I can send and receive messages, but for the life of me I cannot figure out how to display them. i want to display the inbox in table organized like this:
message sender | message subject | message sent date
I ha...
1
votes
1
answer
643
Views
Validation message helper or retrieving validation error
P.S: I've been working with Ruby for less than 48 hours, so expect me to be dumb!
I have set up validation on a model which all works fine. However I want to modify the message retuned by the uniqueness constraint. The message needs to be returned by a method which does some additional processing.
S...
1
votes
1
answer
806
Views
What's the standard file structure of a Ruby project?
Assuming I'm creating a vanilla Ruby project that isn't necessarily a web project, what should my file structure look like? My requirements are:
Has a mechanism for including gems (Gemfile in the root most likely)
Allows me to run the Ruby file directly but also can serve as a library
My stab at t...
1
votes
3
answer
116
Views
Create a hash from a map result
I need to create a hash using the key_name and value from a set of results.
It would be clear if I show you what I have:
results.map{|r| {r.other_model.key_name=>r.value} }
that is giving me this:
[{"api_token"=>"stes"}, {"Name"=>"nononono"}]
But I want this:
{"api_token"=>"stes", "Name"=>"nononono"...
1
votes
3
answer
200
Views
Ruby using step method to return large numbers with delimiter?
(2500..75000).step(2500).to_a
#=> [2500, 5000, 7500, 10000, 12500, 15000, 17500, 20000, 22500, 25000, 27500, 30000, 32500, 35000, 37500, 40000, 42500, 45000, 47500, 50000, 52500, 55000, 57500, 60000, 62500, 65000, 67500, 70000, 72500, 75000]
How do I get the output to be: [ '2,500', '5,000', '7,500...
1
votes
2
answer
689
Views
Rails Table - Dynamic Conditional Font Formatting
I am trying to set the font color of dynamic values as follows: if incident.state_id = 1, then red font, if incident.state_id = 2, then yellow font, if incident.state_id = 3, then red font.
incident.state_id = 1 : state.name = "Pending Investigation"
incident.state_id = 2 : state.name = "Investigat...
1
votes
2
answer
1.7k
Views
Ruby Koans Proxy Project
I'm walking through the Ruby Koans and I have a trouble in about_proxy_object_project.rb
This is my solution
class Proxy
attr_reader :messages
def initialize(target_object)
@object = target_object
# ADD MORE CODE HERE
@messages = []
end
def number_of_times_called(method_name)
@messages.count method_...
1
votes
1
answer
271
Views
syntax error, unexpected keyword_or scope
I'm running Feed.history but It's raised the error above in title because of my scope line in Feed model:
scope :history, -> { or({:end.ne => nil}, {:end.lt => Time.current}) }
what and why?!!
1
votes
1
answer
561
Views
Editing ini files with ruby, clean way preferred
Hello I'm interested in editing an ini file using ruby. By that I mean that I want to read e.g. a variable in the file, change its contents and save the changes back to the file. I would also like to perform the edits in a clean ruby-ish manner. There is this relative gem but as far as I understand...
1
votes
2
answer
67
Views
What happened while using a hash as the parameter when initializing a instance in Ruby?
I defined a class for User, which takes a hash as parameter,
class User
attr_accessor :name, :email
def initialize(attributes = {})
@name = attributes[:name]
@email = attributes[:email]
end
def formatted_email
"#{@name} "
end
end
While initializing in console using parenthesis and empty space synt...
0
votes
0
answer
6
Views
Ruby on Rails, Can I get the current count of connections in Mongoid pool?
I have set min_pool_size to 100 in mongoid.yml but in mongo when running db.serverStatus().connections i only get 30. Is there a way to check how many connections I have in pool?
1
votes
1
answer
238
Views
Ruby Motion how do I change back button's default color?
Is there a way to change the default back button's color blue to my own specified color without having to set it as an image? I want to implement this using Ruby Motion.
1
votes
2
answer
110
Views
How to separate (new,create,delete) actions and show action in Rails for a blog?
Im trying to build a blog and having some issues. The blog have a separate dashboard with its own layout /dashboard. Imagine that I have a model named post. In the blog, the blog post URLs will be like /post/hello-world. Normally its easy to add, edit and delete these posts. I just have to add resou...
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...
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...
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...
1
votes
1
answer
963
Views
Ruby does not detect after installing using RVM
My configurations
Ubuntu 14.04 amd64
I followed this tutorial to install Ruby
Successfully installed ruby.
Closed the Terminal.
Checking
ruby -v
shows
The program 'ruby' can be found in the following packages:
* ruby
* ruby1.8
Try: sudo apt-get install
4.Runs the command
[[ -s "$HOME/.rvm/...
1
votes
1
answer
379
Views
dots in rails URL
I'm trying to add a show page to my devise users but can't seem to get the id value passed properly, how do I create a link to the show page? For some reason rails is doing this to URL
/show.1
users controller:
def show
@user = User.find(params[:id])
end
user/show.html.erb
link to user profile also...
1
votes
1
answer
154
Views
Ruby on Rails - How to set cron on local
Suppose, we have a rake task, to be run like,
rake RAILS_ENV=development parse_and_insert_feed_in_db
We can set this task to be execute repeatedly on server using crontab's.
1 0 * * * rake RAILS_ENV=development parse_and_insert_feed_in_db > /some/dir/file.log
How can we set a rake task to be execu...