Creating rows in a table associated with 2 others

Have models: class Usdzar < ActiveRecord::Base has_many :smoothings has_many :smoothvals, through: :smoothings end class Smoothval < ActiveRecord::Base has_many :smoothprices has_many :usdzars, through: :smoothings end class Smoothing < ActiveRec

Ruby on rails DateTime requires a param

Hi there i just need to require the param start_hour from my form so that i compare it to the database and check if it exist, but when i requiere the param that is in the form like <%= f.datetime_select :start_hour, { :order => [:month, :day, :year,

How can I test the helpers in Rails 4?

With this ApplicationHelper: class ApplicationHelper def my_method link_to 'foo', 'bar' end end and this application_helper_spec: require 'rails_helper' describe ApplicationHelper do describe 'links' do it 'should call a helper method' do expect(help

Heroku app linking to domain providers website

I'm in trouble. I have this website which runs on heroku with a custom domain from another provider. I made the connection between the 2 with the correct DNS. It seemed to work on my browser but it didn't work on other computers, and after clearing m

10.1.4 ruby ​​on rails by michael hartl RED TEST

I'm currently following the Ruby on Rails Tutorial from author Michael Hartl. And i got stuck at chapter 10.1.4 where the test should be GREEN but is currently RED, this is the error message: Started with run options --seed 48963 FAIL["test_valid_sig

Use polymorphic associations with the default scope

I am contributing one of the ruby on rails application over GitHub where I faced the following scenario: I am having following models which I want to convert to make polymorphic: class Comment < ActiveRecord::Base belongs_to :team belongs_to :project

Rails 4 correspond to all routes for a controller

I have a controller with a number of static pages and I would ideally like to route them all with a wildcard. Is it possible to do something like the following? get 'static/:action' Why don't you just use the show action: #config/routes.rb resources

has_one - how to assign_id?

There is a cool feature for has_many in Rails. I can write class Article < AR::Base has_many :comments has_one :another_association and voila! method comment_ids= created, which I can use in strong parameters and mass assignment. Somethind like @arti

Token Authentication for JSON Rails APIs

I make API in rails. For normal authentication we use devise but in API how to implement devise for authentication. gem 'devise_token_auth' Someone prefer this this gem for authentication but there are no tutorial available for that. How to implement

Rails 4 - showing errors in a model that is not Enableecord

I have a tableless model (i.e not saving in the DB), in order to manage a form. After following the instruction set in a Railscast episode, it's mostly working: class PaymentRequest include ActiveModel::Validations include ActiveModel::Conversion ext

Add WWW to the URL when it is not present on Ruby on Rails

I want to force my URL to start with www. when it's not present. I tried the match method, but it seems to ignore the start of the URL, it seems to do something called Route Globbing, that appearently just works with route segments http://guides.ruby

How can I allow users to choose the columns displayed in Rails?

I have a model named Employee that has over a dozen fields making it impractical to display all fields at once. I would like to allow users to choose which columns are displayed by using either a multiple select box or a list of checkboxes, the resul

Custom parameters from view to controller

i'm creating a form where a user can choose a product and a quantity. I need to pass the id value from the object @event to the controller, but i dont know whats the right way to do it. As it is now, it the params[:event_id] field is always nil in th

How to run an RSpec test on a specific line?

I have next spec file: require 'rails_helper' describe Order do it "calculates the total price of the order" do item1 = create(:item) item2 = create(:item, price: 20) order = create(:order) order.items << item1 order.items << item2 o

Why autoload Rails failed with the file is there?

I am setting up Grape on Rails 4.1. I am putting it inside lib according to . I'd like to put helper methods in separated files, file structure is like following: lib |--- api |

the rails reach can not generate a correct SQL

I added a variable in config/application.rb: config.available_account_types = %w(SystemAccount CashAccount DemandAccount LiabilityAccount CreditCardAccount) And generated some scopes in model account.rb: for t in Mypurse::Application.config.available

Rails 4 does not encrypt the content of cookies

Hello I'm trying to encrypt and secure the data contained in my cookies but It seems like the data only gets encoded (base64) This is an example: cookies.signed[:example] = { :value => 'can you see this?', :httponly => true, :expire_after => 30.m

Custom validation of Rails with request Params?

Rails noob , I am trying to write a custom validation but I am dependent on parameters that come from the post request. This example is similar to what I have - in this post model I want to validate that a user didn't already post on some topic, but

Rails 4 fomatting with a minimal error

i have this simple erb code that works perfectly, joint to my i18n.yml file. The idea is to get the client's edit.html.erb page, get the title of that page in my en.yml file and pass that title the @client.fullname variable. Like so: <h1><%= t('c

ActiveAdmin login page

I'm working with my first rails app with activeadmin and I'm working on incorporating devise as the Authentication mechanism. Currently when a user is not authenticated, it's redirecting to the default devise login page. I want to default to an activ

Rails access 2 records at a time

I am trying to print 2 records on one page. I have around 513 database records. I know in ruby you can use something like range.step(2).each do ... , is it possible to do it with rails and an active record collection? like: Users.step(2).each_with_in

Friendly_id | Active record not found

I follow the Railscast Episode Pretty URLs with FriendlyId. I'm on Rails4 and using the 5.0 stable branch on Friendly Id's Github Repo. I followed the Tutorial: My Model Clip.rb: extend FriendlyId friendly_id :title, use: :slugged My Migration: rails

Private Accessors / Attribute-Protected in Rails 4

Supose that I have the following class: class Foo < ActiveRecord::Base belongs_to :bar end In rails console I can do this: foo = foo.bar_id = 3 But this can violates the encapsulation principle. I think that is better idea do: foo = f

Is puma the only HTTP server with multiple threads 4?

I've gotten our stack converted to Rails 4 (yea!) and I'm looking to take advantage of the thread-safe code. Puma works in getting up, stopping it appears to be a different problem :( Is Puma the only multi-threaded rails? Thin -> EventMachine Unicor

Deleting nested attributes does not work

I seem to be unable to delete items using the accepts_nested_attributes_for command but I have done this according to this tutorial and the associated git repo. My models are ... class Job < ActiveRecord::Base has_many :specialties, :inverse_of => :