Re: [Rails] associations - one to many

2016-10-21 Thread Joe Guerra
On Tuesday, October 18, 2016 at 8:48:51 AM UTC-4, Chris Lerum wrote: > > Your line: > params.require(:product).permit(:title, :template, :price, :msrp, > :enddate) > needs to be: > params.require(:product).permit(:title, :template, :price, :msrp, > :enddate, :category_id) > > On Tuesday,

Re: [Rails] associations - one to many

2016-10-18 Thread Chris Lerum
Your line: params.require(:product).permit(:title, :template, :price, :msrp, :enddate) needs to be: params.require(:product).permit(:title, :template, :price, :msrp, :enddate, :category_id) On Tuesday, October 4, 2016 at 3:15:26 PM UTC-4, Joe Guerra wrote: > > Still unsure of what to do... this

Re: [Rails] associations - one to many

2016-10-04 Thread Joe Guerra
Still unsure of what to do... this is my migration to add category {id} to my products table class AddCategoryRefToProducts < ActiveRecord::Migration def change add_reference :products, :category, index: true, foreign_key: true end end On Friday, September 30, 2016 at 3:33:04 PM

Re: [Rails] associations - one to many

2016-09-30 Thread Emmanuel Abia
change to this also...observe the category_id attribute. I hope you have it in your product model <%= simple_form_for(@product) do |f| %> <%= f.error_notification %> <%= f.label :category %> <%= f.collection_select :category_id, Category.all, :id, :name %> <%= f.input

Re: [Rails] associations - one to many

2016-09-30 Thread Emmanuel Abia
The problem is that you have not passed in the category id so it wont get saved. I suggest you: 1. add category_id to your list of permitted product params 2. introduce validations in the product model to guard against missing values On Fri, Sep 30, 2016 at 4:43 PM, Joe Guerra

Re: [Rails] associations - one to many

2016-09-30 Thread Joe Guerra
class ProductsController < ApplicationController before_action :set_product, only: [:show, :edit, :update, :destroy] # GET /products # GET /products.json def index # @search = Product.search(params[:search]) #ransack @search = Product.search(params[:q])

Re: [Rails] associations - one to many

2016-09-30 Thread Emmanuel Abia
Pardon me its the update action code On 30 Sep 2016 4:31 p.m., "Emmanuel Abia" wrote: > Need the code in the controller edit action > > On 30 Sep 2016 4:03 p.m., "Joe Guerra" wrote: > >> Ok, here is my edit products page... >> >> <% if user_signed_in?

Re: [Rails] associations - one to many

2016-09-30 Thread Emmanuel Abia
Need the code in the controller edit action On 30 Sep 2016 4:03 p.m., "Joe Guerra" wrote: > Ok, here is my edit products page... > > <% if user_signed_in? %> > > Editing Product > > <%= render 'form' %> > > <%= link_to 'Show', @product %> | > <%= link_to 'Back',

Re: [Rails] associations - one to many

2016-09-30 Thread Colin Law
On 30 September 2016 at 16:03, Joe Guerra wrote: > Ok, here is my edit products page... And, more importantly, the update method in the controller, which is probably what Emmanuel meant as that is where you should be saving the data after all. Also copy/paste here what

Re: [Rails] associations - one to many

2016-09-30 Thread Joe Guerra
Ok, here is my edit products page... <% if user_signed_in? %> Editing Product <%= render 'form' %> <%= link_to 'Show', @product %> | <%= link_to 'Back', products_path %> <% else %> You must be signed in as administrator to edit the products. <% end %> here is my _form <%=

Re: [Rails] associations - one to many

2016-09-30 Thread Emmanuel Abia
You need to show the code for your edit On 30 Sep 2016 3:51 p.m., "Joe Guerra" wrote: > I've got two tables in my Postgres database: categories and products. > > I have a one to many relationship defined, one category can have many > products. > > > I then created a

[Rails] associations - one to many

2016-09-30 Thread Joe Guerra
I've got two tables in my Postgres database: categories and products. I have a one to many relationship defined, one category can have many products. I then created a reference and migrated the tables. AddCategoryRefToProducts category:references I have this in my models. #product.rb