[Rails] Different selects in one form with same name attribute?

2014-01-04 Thread Srdjan Cengic
Question are at end of the topic. class Product ActiveRecord::Base belongs_to :categoriesend class Category ActiveRecord::Base has_many :productsend Categories table has 2 level nesting, for example. Main category is 'Men', sub-category is 'Accessories' and sub-sub-category is

[Rails] Rails, accepts_nested_attributes_for has_many: through with build

2013-12-20 Thread Srdjan Cengic
I have 3 models: class Product ActiveRecord::Base has_many :product_option_types has_many :option_types, through: :product_option_typesend class OptionType ActiveRecord::Base has_many :product_option_types has_many :products, through: :product_option_typesend class

[Rails] Rails 4, subdomain routing

2013-11-20 Thread Srdjan Cengic
Trying to implement web service in rails through API sub-domain called api. In my hosts file i added line: 127.0.0.1 api.localhost In my routes.rb i set sub-domain, where i only need index action and few manually added restful routes, through following: namespace :api, path: '', :constraints

[Rails] Restful Routing and restful versus non-restful routes

2013-11-18 Thread Srdjan Cengic
So resources :products will create 7 different restful routes for CRUD operations for resource products. For example: products GET /products(.:format) products#index So restful route includes only controller name within itself and :id for operation like edit, show, update, delete. When i

[Rails] Restful routing, restful versus non-restful routes

2013-11-18 Thread Srdjan Cengic
So resources :products will create 7 different restful routes for CRUD operations for resource products. For example: products GET /products(.:format) products#index So restful route includes only controller name within itself and :id for operation like edit, show, update, delete. When i

Re: [Rails] accepts_nested_attributes_for how, example

2013-11-11 Thread Srdjan Cengic
Thanks Colin on reply. I tried with following code, which work good but i don't know how to create row in *votes* table. *// routes.rb* resources :entries, :only =[:new, :create] //* entries_controller.rb* class EntriesController ApplicationController def new @entry = Entry.new(*:user_id

[Rails] Re: accepts_nested_attributes_for how, example

2013-11-11 Thread Srdjan Cengic
Thanks Colin on reply. I tried with following code, which work good so just wanted to ask is this correct solution, for some reason i think this code smell. *// routes.rb* resources :entries, :only =[:new, :create] *// user.rb* class User ActiveRecord::Base has_many :entries end *//

[Rails] accepts_nested_attributes_for how, example

2013-11-10 Thread Srdjan Cengic
I have following tables with following models: users(id, role_id) *has_many :entries* categories(id, category_name) *has_many :entries* entries(id, category_id, user_id) *belongs_to :user, belongs_to :category, has_one :storage* storages(id, title, content, entry_id)*

[Rails] Creation of object which doesn't have model, while creation need to create several entries in other

2013-11-09 Thread Srdjan Cengic
In application user can enter new *post* which contain *title*, *content*of the post and *category* of post. So creating new post will be through some simple html form with few fields. Now i don't know where to put logic for creating new post for following reasons: Post(or posts

[Rails] ActiveRecord and model question

2013-10-20 Thread Srdjan Cengic
Hy, I have some table in my DB like following: *Post(id, title, content, created_at, updated_at)* First question, what type ActiveRecord returns? For example if i do something like: @posts = Post.all, through debugger i can see: #ActiveRecord::Relation *[*#Post id: 1, title: My first post,