ActionView::Template::Error (undefined method `myuserid' for #<Userdetail:0x007f3e631929d8>): - ruby-on-rails

Hi I am trying to create a rails app,My app working fine locally but when I deployed it on Heroku its giving error.I have tried all other solutions on stackoverflow but not any working for me.
Rendered userdetails/new.html.erb within layouts/application (69.0ms)
2014-11-09T17:38:23.427665+00:00 app[web.1]: Started GET "/userdetails/new" for 113.193.105.11 at 2014-11-09 17:38:23 +0000
2014-11-09T17:38:23.511449+00:00 app[web.1]: Completed 500 Internal Server Error in 80ms
2014-11-09T17:38:23.513446+00:00 app[web.1]: app/views/userdetails/new.html.erb:4:in `_app_views_userdetails_new_html_erb__4090279191377710950_69952963663860'
2014-11-09T17:38:23.513443+00:00 app[web.1]: app/views/userdetails/_form.html.erb:24:in `block in _app_views_userdetails__form_html_erb___1876473002485377605_69952963666180'
2014-11-09T17:38:23.511258+00:00 app[web.1]: Rendered userdetails/_form.html.erb (67.7ms)
2014-11-09T17:38:23.430938+00:00 app[web.1]: Processing by UserdetailsController#new as HTML
2014-11-09T17:38:23.513448+00:00 app[web.1]:
2014-11-09T17:38:23.513426+00:00 app[web.1]:
2014-11-09T17:38:23.513429+00:00 app[web.1]: ActionView::Template::Error (undefined method `myuserid' for #<Userdetail:0x007f3e631929d8>):
2014-11-09T17:38:23.513430+00:00 app[web.1]: 21: </div>
2014-11-09T17:38:23.513433+00:00 app[web.1]: 22: <div class="field">
2014-11-09T17:38:23.513435+00:00 app[web.1]: 23: <%= f.label :myuserid , 'User ID'%><br>
2014-11-09T17:38:23.513436+00:00 app[web.1]: 24: <%= f.text_field :myuserid %>
2014-11-09T17:38:23.513438+00:00 app[web.1]: 25: </div>
2014-11-09T17:38:23.513439+00:00 app[web.1]: 26: <div class="field">
2014-11-09T17:38:23.513441+00:00 app[web.1]: 27: <%= f.label :birthday %><br>
2014-11-09T17:38:23.513445+00:00 app[web.1]: app/views/userdetails/_form.html.erb:1:in `_app_views_userdetails__form_html_erb___1876473002485377605_69952963666180'
My userdetail/new.html.erb looks like
<h1>New userdetail</h1>
<%= render 'form',userdetail: #userdetail %>
<%= link_to 'Back', userdetails_path %>
and My userdetail/_form.html looks like
<%= form_for(#userdetail) do |f| %>
<% if #userdetail.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#userdetail.errors.count, "error") %> prohibited this userdetail from being saved:</h2>
<ul>
<% #userdetail.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :first_name %><br>
<%= f.text_field :first_name %>
</div>
<div class="field">
<%= f.label :last_name %><br>
<%= f.text_field :last_name %>
</div>
<div class="field">
<%= f.label :myuserid , 'User ID'%><br>
<%= f.text_field :myuserid %>
</div>
<div class="field">
<%= f.label :birthday %><br>
<%= f.date_select :birthday %>
</div>
<div class="field">
<%= f.label :gender %><br>
<%= f.text_field :gender %>
</div>
<div class="field">
<%= f.label :contact_number %><br>
<%= f.text_field :contact_number %>
</div>
<div class="field">
<%= f.label :address %><br>
<%= f.text_area :address %>
</div>
<div class="field">
<%= f.label :country %><br>
<%= f.text_field :country %>
</div>
<div class="field">
<%= f.label :state %><br>
<%= f.text_field :state %>
</div>
<div class="field">
<%= f.label :city %><br>
<%= f.text_field :city %>
</div>
<div class="field">
<%= f.label :gre_date %><br>
<%= f.date_select :gre_date %>
</div>
<%= f.hidden_field :user_id %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
My userdetail controller looks like
class UserdetailsController < ApplicationController
before_action :set_userdetail, only: [:show, :edit, :update, :destroy]
#User can only edit or destroy its own details
before_action :correct_user, only: [:edit, :update, :destroy]
# GET /userdetails
# GET /userdetails.json
def index
#userdetails = Userdetail.all
end
# GET /userdetails/1
# GET /userdetails/1.json
def show
end
# GET /userdetails/new
def new
#userdetail = Userdetail.new
end
# GET /userdetails/1/edit
def edit
end
# POST /userdetails
# POST /userdetails.json
def create
#userdetail = Userdetail.new(userdetail_params)
#userdetail.user_id = current_user.id
respond_to do |format|
if #userdetail.save
format.html { redirect_to #userdetail, notice: 'Userdetail was successfully created.' }
format.json { render :show, status: :created, location: #userdetail }
else
format.html { render :new }
format.json { render json: #userdetail.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /userdetails/1
# PATCH/PUT /userdetails/1.json
def update
respond_to do |format|
if #userdetail.update(userdetail_params)
format.html { redirect_to #userdetail, notice: 'Userdetail was successfully updated.' }
format.json { render :show, status: :ok, location: #userdetail }
else
format.html { render :edit }
format.json { render json: #userdetail.errors, status: :unprocessable_entity }
end
end
end
# DELETE /userdetails/1
# DELETE /userdetails/1.json
def destroy
#userdetail.destroy
respond_to do |format|
format.html { redirect_to userdetails_url, notice: 'Userdetail was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_userdetail
#userdetail = Userdetail.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def userdetail_params
params.require(:userdetail).permit(:first_name, :last_name, :myuserid, :birthday, :gender, :contact_number, :address, :country, :state, :city, :gre_date)
end
def correct_user
#user = #userdetail.user_id
redirect_to( userdetails_url) unless #user == current_user.id
end
end
My user detail model looks like
class Userdetail < ActiveRecord::Base
belongs_to :user
#validates that one user can create just one user details
validates_uniqueness_of :user_id, :message => "details already exist"
end
My db schema looks like
ActiveRecord::Schema.define(version: 20141108175213) do
create_table "posts", force: true do |t|
t.text "issue", default: "", null: false
t.text "description", default: "", null: false
t.integer "rating"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "topic_id"
end
create_table "topics", force: true do |t|
t.text "issue", default: "", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "userdetails", force: true do |t|
t.string "first_name"
t.string "last_name"
t.date "birthday"
t.string "gender"
t.string "contact_number"
t.text "address"
t.string "country"
t.string "state"
t.string "city"
t.date "gre_date"
t.datetime "created_at"
t.datetime "updated_at"
t.string "myuserid"
t.integer "user_id"
end
add_index "userdetails", ["myuserid"], name: "index_userdetails_on_myuserid", unique: true
add_index "userdetails", ["user_id"], name: "index_userdetails_on_user_id"
create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
Please tell me answer. I generated app's view and model using command rails g scaffold userdetail but added 'myuserid' column later.Please see any if there is any other fault inn my code and suggest correction
Also my directory contain automatically generated duplicate files with ~ at the end of name, Any idea ?

I found the answer, when i ran rails console in heroku I found that myuserid column was not created in heroku. When i check my migration files I found that the migration file creating myuserid column was accidentally deleted. I recreated that file and my app start working.

Related

How to fixed the value in input field and also set default zero

now i doing a form that can add product to outlet.This form is create at the outletproduct page
So when i click to a product info page have a button (add product to outlet) then go to the form which located at outletproduct page. Now i need to set these things
1.I have create the form out but at the product name field there i need to display product name i choose to be fixed and cannot be change.(Example, click on the product fish then click button then the product name should be fish.)
2.The selling_price and last_cost will need to show the product price and cost in the input field there but this can be change(Example, at product page price is $2 and cost is $1, then here the input field will be selling_price $2 and last_cost $1.)
i have try do but it won't work.
I have update some pic about UI.
OutletProduct Controller
class OutletProductsController < ApplicationController
def new
#outlet_product = OutletProduct.new
#product = Product.all
#outlet = Outlet.all
#category = Category.all
end
def index
end
def show
end
def create
#outlet_product = OutletProduct.new(outlet_product_params)
#category_id = Category.all
#outlet_id = Outlet.all
#product_id = Product.all
if #outlet_product.save
flash[:success] = "Succesful create!"
redirect_to #outlet_product
else
render 'new'
end
end
def edit
end
def outlet_product_params
params.require(:outlet_product).permit(:product_id, :outlet_id, :quantity,
:selling_price ,:last_cost)
end
end
new.html.erb
<h1>Add product to outlet</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_with(model: #outlet_product, local: true) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.label :product_name %>
<%= f.text_field :#product.name ,class: "form-select" %>
<%= f.label :quantity %>
<%= f.number_field :quantity%>
<%= f.label :selling_price %>
<%= f.number_field :selling_price, #product.price , class: 'form-control' %>
<%= f.label :last_cost %>
<%= f.number_field :last_cost,#product.cost, class: 'form-control' %>
<%= f.label :outlet_id %>
<%= f.select(:outlet_id, Outlet.all.collect { |l| [ l.name, l.id] }, {class: "form-select"}) %>
<%= f.submit "Submit", class: "btn btn-primary" %>
<% end %>
</div>
</div>
OutletProduct migration in schema
create_table "outlet_products", force: :cascade do |t|
t.integer "outlet_id"
t.integer "product_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.decimal "selling_price"
t.decimal "last_cost"
t.decimal "quantity"
end
product migration in schema
create_table "products", force: :cascade do |t|
t.string "name"
t.integer "quantity"
t.integer "price"
t.integer "category_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.decimal "cost"
end
Product page
Product info page]
form page
Hi you can define all the default values in view like below
<%= f.label :selling_price %>
<%= f.number_field :selling_price, 0 , class: 'form-control' %>
or if you wanted to keep it by default in the database, then you can make changes in migration files as below:
create_table "products", force: :cascade do |t|
t.string "name", default: 'fish'
t.integer "quantity", default: 0
t.integer "price"
t.integer "category_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.decimal "cost"
end
I hope this is what you are trying to achieve.

getting "ActionController::ParameterMissing in HomepageController#newbands"

I am trying to print out a form using the simple_form gem but I am getting this error:
ActionController::ParameterMissing in HomepageController#newbands
param is missing or the value is empty: band
homepage_controller.rb
class HomepageController < ApplicationController
def index
end
def bands
end
def newbands
#band = Band.new
#band = Band.create(band_params)
if #band.save
redirect_to "/newbands"
else
render "/"
end
end
private
def band_params
params.require(:band).permit(:name, :country, :members, :genre)
end
end
newbands.html.erb
<%= simple_form_for #band do |b| %>
<%= b.input :name %>
<%= b.input :country %>
<%= b.input :members %>
<%= b.input :genre %>
<%= b.button :submit %>
<% end %>
schema.rb
ActiveRecord::Schema[7.0].define(version: 2022_03_14_133839) do
create_table "bands", force: :cascade do |t|
t.string "name"
t.string "country"
t.integer "members"
t.string "genre"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end

Rails Not able to save data, association

I'm doing a parking permit website. The problem I met is that I'm not able to save my data to the PERMIT database which associated with the USER database. The problem i think is I didn't bring the user to the permit(Maybe i missed something). I found out the error when I trying to save from Permit.errors.full_messages is ["User must exist"]. Any help is appreciated, Thank you!
Schema.rb
ActiveRecord::Schema.define(version: 20160920143651) do
create_table "permits", force: :cascade do |t|
t.string "vehicle_type"
t.string "name"
t.string "studentid"
t.string "department"
t.string "carplate"
t.string "duration"
t.date "permitstart"
t.date "permitend"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_permits_on_user_id"
end
create_table "users", force: :cascade do |t|
t.string "name"
t.string "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "password_digest"
t.integer "user_type"
end
end
Create_permit.rb
class CreatePermits < ActiveRecord::Migration[5.0]
def change
create_table :permits do |t|
t.string :vehicle_type
t.string :name
t.string :studentid
t.string :department
t.string :carplate
t.string :duration
t.date :permitstart
t.date :permitend
t.references :user, foreign_key: true
t.timestamps
end
add_index :permits, :user_id
end
end
Permit_controller
class PermitsController < ApplicationController
before_action :set_permit, only: [:show, :destroy]
def index
#permits = Permit.all
end
def new
#permits = Permit.new
end
def create
#permits = Permit.new(permit_params)
if #permits.save
redirect_to #permits
else
redirect_to contact_path
end
end
def destroy
Permit.destroy_all(user_id: 1)
respond_to do |format|
format.html { redirect_to users_url, notice: 'Permit was successfully canceled.' }
format.json { head :no_content }
end
end
def show
#permits = Permit.find(params[:id])
end
def update
respond_to do |format|
if #permits.update(user_params)
format.html { redirect_to #user, notice: 'Permit was successfully updated.' }
format.json { render :show, status: :ok, location: #user }
else
format.html { render :edit }
format.json { render json: #user.errors, status: :unprocessable_entity }
end
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_permit
#permits = Permit.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def permit_params
params.require(:permit).permit(:vehicle_type, :name, :studentid, :department, :carplate, :duration, :permitstart, :permitend)
end
end
user.rb
class User < ApplicationRecord
has_many :permits
has_secure_password
end
Permit.rb
class Permit < ApplicationRecord
belongs_to :user
end
permit/new.html.erb
<% provide(:title, 'New Permit') %>
<h1>Permit Application</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(#permits) do |f| %>
<%= f.label :"Vehicle" %>
<%= f.text_field :vehicle_type, class: 'form-control' %>
<%= f.label :"License Plate" %>
<%= f.text_field :carplate, class: 'form-control' %>
<%= f.label :"Student ID" %>
<%= f.text_field :studentid, class: 'form-control' %>
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
<%= f.label :"Department of applicant" %>
<%= f.text_field :department, class: 'form-control' %>
<%= f.label :permit_start %>
<%= f.date_select :permitstart, class: 'form-control' %>
<%= f.label :permit_end %>
<%= f.date_select :permitend, class: 'form-control' %>
<%= f.submit "Submit", class: "btn btn-primary" %>
<% end %>
</div>
</div>
I guess you are using Rails 5. The problem is you have belongs_to association on permit that is belongs to user but while creating permit you are not associating any user with it and in Rails 5 it is mandatory to assign data to belongs_to association i.e you can not save permit when it don't have user_id so try to assign a user_id to permit. refer this for change to rails 5 belongs_to association
Where exactly is your error ? If in update action, you have to change your before_action. You must add there :update action.
before_action :set_permit, only: [:show, :destroy, :update]

Can't save my data into sqlite database

I am trying to implement a Parking Permit application page using ROR. I couldn't get my data saved into the database. The permit database is associated with the user also. The program won't save the data and execute the else statement. There is no error generated, i think i have missed something but i don't know the exact problem. Any help is appreciated!
Permit_controller.rb
class PermitsController < ApplicationController
before_action :set_permit, only: [:show, :destroy]
def index
#permits = Permit.all
end
def new
#permits = Permit.new
end
def create
#permits = Permit.new(permit_params)
if #permits.save
redirect_to root_path
else
redirect_to contact_path
end
end
def destroy
end
def show
#permits = Permit.find(params[:id])
end
private
# Use callbacks to share common setup or constraints between actions.
def set_permit
#permits = Permit.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def permit_params
params.require(:permit).permit(:vehicle_type, :name, :studentid, :department, :carplate,:permitstart, :permitend)
end
end
Permit.rb
class Permit < ApplicationRecord
belongs_to :user
end
Create_permit.rb
class CreatePermits < ActiveRecord::Migration[5.0]
def change
create_table :permits do |t|
t.string :vehicle_type
t.string :name
t.string :studentid
t.string :department
t.string :carplate
t.date :permitstart
t.date :permitend
t.references :user, foreign_key: true
t.timestamps
end
add_foreign_key :permits, :user
add_index :permits, [:user_id, :created_at]
end
end
User.rb
class User < ApplicationRecord
has_secure_password
has_many :permits
end
#book pg 264 Validation
permit/new.html.erb
<% provide(:title, 'New Permit') %>
<h1>Permit Application</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(#permits) do |f| %>
<%= f.label :"Vehicle" %>
<%= f.text_field :vehicle_type, class: 'form-control' %>
<%= f.label :"License Plate" %>
<%= f.text_field :carplate, class: 'form-control' %>
<%= f.label :"Student ID" %>
<%= f.text_field :studentid, class: 'form-control' %>
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
<%= f.label :"Department of applicant" %>
<%= f.text_field :department, class: 'form-control' %>
<%= f.label :permit_start %>
<%= f.date_select :permitstart, class: 'form-control' %>
<%= f.label :permit_end %>
<%= f.date_select :permitend, class: 'form-control' %>
<%= f.submit "Submit", class: "btn btn-primary" %>
<% end %>
</div>
</div>
schema.rb
ActiveRecord::Schema.define(version: 20160921071908) do
create_table "permits", force: :cascade do |t|
t.string "vehicle_type"
t.string "name"
t.string "studentid"
t.string "department"
t.string "carplate"
t.date "permitstart"
t.date "permitend"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_permits_on_user_id"
end
create_table "users", force: :cascade do |t|
t.string "name"
t.string "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "password_digest"
t.integer "user_type"
end
end
check with this #permits.save!.
it shows the exact error.
module ApplicationHelper
#for current user to use through out the app
def current_user
#current_user ||= session[:current_user_id] && User.find_by_id(session[:current_user_id]) # Use find_by_id to get nil instead of an error if user doesn't exist
end
end
and
def create
#permits = Permit.new(permit_params)
#permits.user = current_user
if #permits.save
redirect_to root_path
else
redirect_to contact_path
end
end
test it
Or you can just say that a permit has a single user and avoid the confusion.
#models/permit.rb
class Permit < ApplicationRecord
has_one :user
end
#controllers/permit_controller.rb
def create
#user = User.find(session[:user_id]) #use your session variable
#permits = Permit.new(permit_params)
if #permits.save
#user.permits << #permits
redirect_to root_path
else
redirect_to contact_path
end
end
It will save permits for the logged in user.

Unpermitted parameters on multiple paperclip file uploads Rails4

I've got a ruby 2.0.0 and rails 4.0.0 app that has a 'Guitar' and 'Photos' model. I've used paperclip to upload a single file in Rails3, but am new to uploading multiple files in Rails 4. I created the second model to hold said photos, and read up on strong parameters, etc. I'm getting an error when attempting to add 3 photos to a guitar. In the logs: "Unpermitted parameters: photos_attributes". I've tried adding photos_attributes to the whitelist and no joy. I'm pulling my hair out here - there's no error in the web view, but when I console in and type 'Photo.all', I get nothing. What am I doing wrong? I'm kind of a newbie, please be gentle.
guitar.rb
class Guitar < ActiveRecord::Base
belongs_to :user
has_many :photos
accepts_nested_attributes_for :photos
end
photo.rb
class Photo < ActiveRecord::Base
belongs_to :guitar
has_attached_file :photo, styles: {
thumb: '100x100>',
square: '200x200#',
medium: '300x300>',
large: '600x6003'
}
end
guitars_controller.rb
class GuitarsController < ApplicationController
before_action :set_guitar, only: [:show, :edit, :update, :destroy]
# GET /guitars
# GET /guitars.json
def index
#guitars = Guitar.all
end
# GET /guitars/1
# GET /guitars/1.json
def show
end
# GET /guitars/new
def new
#guitar = current_user.guitars.build
3.times {#guitar.photos.build}
end
# GET /guitars/1/edit
def edit
3.times {#guitar.photos.build}
end
# POST /guitars
# POST /guitars.json
def create
#guitar = current_user.guitars.build(guitar_params)
respond_to do |format|
if #guitar.save
format.html { redirect_to #guitar, notice: 'Guitar was successfully created.' }
format.json { render action: 'show', status: :created, location: #guitar }
else
format.html { render action: 'new' }
format.json { render json: #guitar.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /guitars/1
# PATCH/PUT /guitars/1.json
def update
respond_to do |format|
if #guitar.update(guitar_params)
format.html { redirect_to #guitar, notice: 'Guitar was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: #guitar.errors, status: :unprocessable_entity }
end
end
end
# DELETE /guitars/1
# DELETE /guitars/1.json
def destroy
#guitar.destroy
respond_to do |format|
format.html { redirect_to guitars_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_guitar
#guitar = Guitar.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def guitar_params
params.require(:guitar).permit(:make, :model, :year, :color, :serial, :price, :condition, :kind, :bodykind, :frets, :oneowner, :user_id, :description, :photos_attributes)
end
end
views/guitar/_form.html.erb
<%= form_for #guitar, :html => { :multipart => true } do |f| %>
<% if #guitar.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#guitar.errors.count, "error") %> prohibited this guitar from being saved:</h2>
<ul>
<% #guitar.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :make %><br>
<%= f.text_field :make %>
</div>
<div class="field">
<%= f.label :model %><br>
<%= f.text_field :model %>
</div>
<div class="field">
<%= f.label :year %><br>
<%= f.text_field :year %>
</div>
<div class="field">
<%= f.label :color %><br>
<%= f.text_field :color %>
</div>
<div class="field">
<%= f.label :serial %><br>
<%= f.text_field :serial %>
</div>
<div class="field">
<%= f.label :price %><br>
<%= f.text_field :price %>
</div>
<div class="field">
<%= f.label :condition %><br>
<%= f.number_field :condition %>
</div>
<div class="field">
<%= f.label :kind %><br>
<%= f.text_field :kind %>
</div>
<div class="field">
<%= f.label :bodykind %><br>
<%= f.text_field :bodykind %>
</div>
<div class="field">
<%= f.label :frets %><br>
<%= f.text_field :frets %>
</div>
<div class="field">
<%= f.label :oneowner %><br>
<%= f.check_box :oneowner %>
</div>
<div class="field">
<%= f.label :extended_description %><br>
<%= f.text_area :description %>
</div>
<%= f.fields_for :photos do |builder| %>
<%= builder.label :photo, "Image File" %>
<%= builder.file_field :photo %>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
db/schema.rb
ActiveRecord::Schema.define(version: 20131014195859) do
create_table "guitars", force: true do |t|
t.string "make"
t.string "model"
t.string "year"
t.string "color"
t.string "serial"
t.string "price"
t.integer "condition"
t.string "kind"
t.string "bodykind"
t.string "frets"
t.boolean "oneowner"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "description"
end
add_index "guitars", ["user_id"], name: "index_guitars_on_user_id", using: :btree
create_table "photos", force: true do |t|
t.integer "guitar_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "photo_file_name"
t.string "photo_content_type"
t.integer "photo_file_size"
t.datetime "photo_updated_at"
end
create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.string "city"
t.string "state"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end
There was a typo.
:photos_attributes => [:photo]
Replace existing code with following and try to run the app.
def guitar_params
params.require(:guitar).permit(:make, :model, :year, :color, :serial, :price, :condition, :kind, :bodykind, :frets, :oneowner, :user_id, :description, :photos_attributes [:photo])
end
Or you can check out the following link where i have created one sample app with nested attributes.
Nested Attributes Example

Resources