Thursday, 15 September 2011

methods - Rails 4 Has_One Model Associations/ Retrieving from DB -



methods - Rails 4 Has_One Model Associations/ Retrieving from DB -

i'm stuck. i've read http://guides.rubyonrails.org/association_basics.html#the-has-one-association , http://guides.rubyonrails.org/active_record_querying.html , no closer solving problem.

i have belongs_to, has_one model association. in case it's user has_one booth , booth belongs_to user. i'm trying should simple, create link users have created booth can view booth created.

to accomplish this, i'm trying create 'user_booth' method. i've tried 100 different variations, should work i've read:

def user_booth @booth = current_user.booth.find_by(id: params[:id]) end

well, of course of study didn't work. i've tried many variations similar this:

def user_booth booth.find_by(id: params[:id]) end

when check database, saves intended to, can't seem phone call on right booth associated right user. can lead me in new direction? i'm exclusively stuck.

here show method in booths controller:

def show @booth = booth.find(params[:id]) end

i should include booth migration:

class createbooths < activerecord::migration def alter create_table :booths |t| t.string :name t.references :user, index: true t.timestamps null: false end end end

thanks million!

ruby-on-rails-4 methods rails-models

No comments:

Post a Comment