Questions tagged [activemodel]

A toolkit for building modeling frameworks like Active Record. Rich support for attributes, callbacks, validations, serialization, internationalization, and testing.

ActiveModel brings many of ActiveRecord's features (such as validations and callbacks) to non-ActiveRecord classes.

707 questions
0
votes
1 answer

Use model of diiferent name in a different controller

I have a controller FormsController and a Active Model ApplicationForm. I have made this model by including include ActiveModel::Validations, include ActiveModel::Conversion, extend ActiveModel::Naming. When I'm using @form=ApplicationForm I'm…
dushyantashu
  • 523
  • 3
  • 9
  • 16
0
votes
2 answers

Error while typing rails server command

I am a beginner.I am trying to launch rails server using the command.But I am getting an error. I tried searching in the google but no results.I will attach a picture of the log I got when I executed that command.
mRbOneS
  • 121
  • 1
  • 14
0
votes
2 answers

Creating associations with new() versus create()

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,…
s_dolan
  • 1,196
  • 1
  • 9
  • 21
0
votes
1 answer

How to use FactoryGirl to create data with has_many through association and some not null column

I have a model like this class Article < ActiveRecord::Base has_many :comments has_many :details, :through => :comments end class Comment < ActiveRecord::Base belongs_to :article belongs_to :detail end class Detail < ActiveRecord::Base …
0
votes
1 answer

Callbacks - Set field on model

I am trying the following - I have Models: Tales, Books, Keywords class Tale < ActiveRecord::Base has_many :tale_culture_joins has_many :cultures, through: :tale_culture_joins has_many :tale_purpose_joins has_many :purposes, through:…
0
votes
1 answer

How do I tell *which* validator caused an error?

I'm debugging this problem with devise-- despite my best efforts I am still getting an error "password can't be blank" when updating a user without providing a password. I have tried the official solution, as well as the solution suggested in this…
joshwa
  • 1,660
  • 3
  • 17
  • 26
0
votes
1 answer

ActiveModel::ForbiddenAttributesError when executing a build inside an update action

I am getting a pesky ActiveModel::ForbiddenAttributesError, and I can't find how to fix it. I was following this guide: https://rbudiharso.wordpress.com/2010/07/07/dynamically-add-and-remove-input-field-in-rails-without-javascript/ and everything…
Techmago
  • 380
  • 4
  • 18
0
votes
1 answer

find order by closest to number

How can I arrange order in Model.where(...).order() to sort the items based on proximity of a number field to assign number? So, when I request to order for 4, (1...6) would be something like this: [4,5,3,6,2,1]
Michal
  • 733
  • 2
  • 6
  • 23
0
votes
4 answers

ruby one-liner for this possible?

Any chance the 2nd and 3rd lines can be combined in an one-liner and hopefully save one valuable? def self.date_format record = find_by_key('strftime') record ? record.value : "%Y-%b-%d' end the above function in a Config model try to fetch a…
ohho
  • 50,879
  • 75
  • 256
  • 383
0
votes
1 answer

Rail's strong_parameters not marking Array's Hashes as Permitted

I've got a bit of a puzzler on for strong_parameters. I'm posting a large array of JSON to get processed and added as relational models to a central model. It looks something like this: { "buncha_data": { "foo_data" [ { "bar":…
Mojowen
  • 437
  • 1
  • 4
  • 17
0
votes
1 answer

Is it possible to validate against field converted to symbol?

I've got an array of symbols and I would like to use validate_inclusion_of to verify that a field in my model is one of those values in the array. The issue is that the field being compared is a string. Obviously I could convert the array to store…
Dan
  • 3,246
  • 1
  • 32
  • 52
0
votes
1 answer

False url helper for Rails Model

I have a controller mounted at the root of an Engine with the same name module Contacts class ContactsController < ApplicationController ... end end Contacts::Engine.routes.draw do root 'contacts#index' resources :contacts, :path => '/' …
SystematicFrank
  • 16,555
  • 7
  • 56
  • 102
0
votes
1 answer

How to link model to controller action

I have a Slider model in my project and it has a lot of polymorphic associations with other model like Product, Manufacturer, Article and etc. So, when I use 'show' action with one of the models I also show related Slider. It's ok. But sometimes I…
Grindel
  • 3
  • 4
0
votes
0 answers

Active record Query methods for simple class

I have created class using Active Model,it is working as expected ,but am having few requirements 1) I want to use all method for that class. 2) Same way i want to use some query methods like where method for that class. 3) I want to create…
Jenorish
  • 1,694
  • 14
  • 19
0
votes
1 answer

Rails form_for method not responding to html options

I have an active model model that I would like to use form_for with. form_for(@item, url: (params[:action] == 'edit' ? api_item_path(datasheet_id: params[:datasheet_id], item_id: params[:item_id]) : api_items_path), html: {method: (params[:action]…
user2536065