Rails shows wrong forum path - ruby-on-rails

I made Forum model which belongs to Category and in show view of every category each forum from that category needs to be showed, but links are pointing at wrong paths (for example, in category 4 I have only one forum which points to category/1/forum/1 and category 1 doesn't even exist).
One more note: each category has it's position field (integer) and they're sorted with that field in ascending order. Category 4 have position 1, but why would that number be on the place of category id in url?
When I try to access /category/4/forum/1 I get the error "Couldn't find Category with 'id'=1"
CategoriesController
class CategoriesController < ApplicationController
def index
categories_ordered
end
def new
#category = Category.new
categories_ordered
end
def create
#category = Category.new(category_params)
categories_ordered
if #category.save
redirect_to forums_path, notice: "Kategorija je uspešno kreirana."
else
render "new"
end
end
def show
find_category
find_forums
end
def edit
find_category
end
def update
find_category
if #category.update(category_params)
redirect_to category_path(#category), notice: "Kategorija je uspešno ažurirana."
else
render "edit"
end
end
def destroy
find_category
#category.destroy
redirect_to forums_path, notice: "Kategorija je uspešno obrisana."
end
private
def category_params
params.require(:category).permit(:name, :description, :position)
end
def find_category
#category = Category.find(params[:id])
end
def find_forums
#forums = #category.forums.all
end
def categories_ordered
#categories = Category.all.order("position ASC")
end
end
ForumsController
class ForumsController < ApplicationController
def new
find_category
#forum = #category.forums.new
end
def create
#category = Category.find(params[:category_id])
#forum = #category.forums.create(forum_params)
if #forum.save
redirect_to category_path(#category), notice: "Forum je uspešno kreiran."
else
render "new"
end
end
def show
find_category
find_forum
end
def edit
find_category
find_forum
end
def update
find_category
find_forum
if #forum.update(forum_params)
redirect_to forum_path(#forum), notice: "Forum je uspešno ažuriran."
else
render "edit"
end
end
private
def forum_params
params.require(:forum).permit(:title, :description)
end
def find_category
#category = Category.find(params[:category_id])
end
def find_forum
#forum = #category.forums.find(params[:id])
end
end
categories#show
<% authorize %>
<h2><%= #category.name %></h2>
<p><%= #category.description %></p>
<div class="list-group">
<% #category.forums.each do |f| %>
<a href="<%= forum_path(f) %>" class="list-group-item">
<h4 class="list-group-heading"><%= f.title %></h4>
<p class="list-group-text">
<%= f.description %>
</p>
</a>
<% end %>
</div>
<% if is_admin? %>
<%= link_to new_forum_path, class: "btn btn-primary" do %>
<span class="glyphicon glyphicon-plus"></span> Dodaj forum
<% end %>
<%= link_to edit_category_path(#category), class: "btn btn-primary" do %>
<span class="glyphicon glyphicon-pencil"></span> Izmeni
<% end %>
<%= link_to category_path(#category), class: "btn btn-danger", method: :delete, data: { confirm: "Da li ste sigurni da želite obrisati ovu kategoriju?" } do %>
<span class="glyphicon glyphicon-trash"></span> Obriši
<% end %>
<% end %>
routes.rb
Rails.application.routes.draw do
root "welcome#index"
get "start" => "welcome#index", as: "index"
get "registration" => "users#new", as: "register"
get "login" => "sessions#new", as: "login"
post "login" => "sessions#create"
get "logout" => "sessions#destroy", as: "logout"
get "users" => "users#index", as: "users"
post "users" => "users#create"
get "profile" => "users#show", as: "profile"
get "user/:id" => "users#show", as: "user"
get "user/:id/edit" => "users#edit", as: "edit_user"
patch "user/:id" => "users#update"
delete "user/:id" => "users#destroy"
get "categories/add" => "categories#new", as: "new_category"
get "category/:id" => "categories#show", as: "category"
patch "category/:id" => "categories#update"
delete "category/:id" => "categories#destroy"
get "category/:id/edit" => "categories#edit", as: "edit_category"
get "terms" => "welcome#terms", as: "terms"
get "wh" => "bugs#new", as: "wh"
get "bugs" => "bugs#index", as: "bugs"
post "bugs" => "bugs#create"
get "bug/:id" => "bugs#show", as: "bug"
delete "bug/:id" => "bugs#destroy"
get "forum" => "categories#index", as: "forums"
get "category/:category_id/forum/add" => "forums#new", as: "new_forum"
get "category/:category_id/forum/:id" => "forums#show", as: "forum"
get "category/:category_id/forum/:id/edit" => "forums#edit", as: "edit_forum"
patch "category/:category_id/forum/:id" => "forums#update"
delete "category/:category_id/forum/:id" => "forums#destroy"
resources :users
resources :sessions
resources :categories do
resources :forums
end
resources :bugs
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

Error is partially solved; I just had to use different parameters with ForumsController (category_id for categories and id for forums).
def find_category
#category = Category.find(params[:category_id])
end
def find_forum
#forum = #category.forum.find(params[:id])
end
And change forum routes accordingly.
It looks like problem still isn't solved. I changed this parts but I still have problems with URLs. Now category and forums IDs are mixed in url (instead of /category/4/forum/1 it shows /category/1/forum/4).
Edit: Problem is finally solved! This answer gave me an idea what I should do. I just had to specify #category with paths too (just changing two lines):
<div class="list-group">
<% #category.forums.each do |f| %>
<a href="<%= forum_path(#category, f) %>" class="list-group-item">
<h4 class="list-group-heading"><%= f.title %></h4>
<p class="list-group-text">
<%= f.description %>
</p>
</a>
<% end %>
</div>
<% if is_admin? %>
<%= link_to new_forum_path(#category), class: "btn btn-primary" do %>
<span class="glyphicon glyphicon-plus"></span> Dodaj forum
<% end %>

Related

Add checkbox to edit bool value of user in devise in Rails

I have created a user using devise gem. I have added a column admin to the User table which has boolean value. Now what I need is to add checkboxes after every user in users_page and give a feature so that when the checkbox is checked the value of admin column changes to true. How can I add the functionality?
users_controller.rb
class UsersController < ApplicationController
def users_page
#users = User.all
end
def change_user_role
#user = User.find(params[:id])
format.html { redirect_to users, notice: 'Role changed successfully' }
end
def destroy
#user = User.find(params[:id])
#user.destroy
if #user.destroy
redirect_to root_url, notice: "User deleted."
end
end
end
users_page.html.erb
<h1>Users</h1>
<% #users.each do |user| %>
<h5><%= user.email %></h5>
<%= user.admin %>
<%= form_tag({controller: "users", action: "change_user_role"}, method: "get") do %>
<%= check_box_tag(:admin, checked: false) %>
<p><%= submit_tag 'Submit Answer' %></p>
<% end %>
<br>
<%= link_to "Destroy", admin_destroy_user_path(user), method: :delete, data: { confirm: "You sure?" } %>
<% end %>
routes.rb
Rails.application.routes.draw do
root to: 'pages#home'
get 'users/users_page'
devise_for :users
match 'users/:id' => 'users#destroy', :via => :delete, :as => :admin_destroy_user
get 'users#change_user_role'
end
Here I should submit the value of the checkbox in users_page to change_user_role and update the value in db and redirect it to users_page. How can I do that?
First of all, change your get method to put in your routes.rb because you'll be updating the resource in database:
Rails.application.routes.draw do
root to: 'pages#home'
get 'users/users_page'
devise_for :users
match 'users/:id' => 'users#destroy', :via => :delete, :as => :admin_destroy_user
// it will require user id in your url
resources :users do
member do
put :change_user_role
end
end
end
More on routes here
Then change your view to something like this:
<h1>Users</h1>
<% #users.each do |user| %>
<h5><%= user.email %></h5>
<%= form_for(user, url: change_user_role_user_path(user)) do |f| %>
<%= f.check_box(:admin) %>
<p><%= f.submit 'Submit Answer' %></p>
<% end %>
<br>
<%= link_to "Destroy", admin_destroy_user_path(user), method: :delete, data: { confirm: "You sure?" } %>
<% end %>
More on forms here
Your controller should look something like this:
class UsersController < ApplicationController
def users_page
#users = User.all
end
def change_user_role
#user = User.find(params[:id])
// if user is updated successfully then redirect
if(#user.update_attributes(user_params)
format.html { redirect_to users, notice: 'Role changed successfully' }
end
end
def destroy
#user = User.find(params[:id])
if #user.destroy
redirect_to root_url, notice: "User deleted."
end
end
// new method added to allow specific attributes only and discarding other malicious attributes that user may send
def user_params
params.require(:user).permit(:admin)
end
end
More on parameters here

Ruby Couldn't find ServiceOrder with 'id'=

I'm setting up a in-app notification to show all the notifications that the user has however I am getting an can't find ID error. I am following this guide here https://www.youtube.com/watch?v=KOs8f8TnwZs.
I want to give notifications every time a Service Order gets a new Request associated with it.
Do you know what could be causing this?
I have tried going into my routes and adding something like this:
resources :service_orders do
resources :requests
end
But it didnt work, and it just made the requests route not work.
The code that I newly added is:
(#service_order.users.uniq - [current_user]).each do |user|
Notification.create(recipient: user, actor: current_user, action: "posted", notifiable: #request)
end
And thats whats causing the error, #service_order isn't being found for some weird reason.
My Request Controller is:
class RequestsController < ApplicationController
before_action :set_request, only: [:show, :edit, :update, :destroy]
before_action :old_request, only: [:show, :index, :update]
before_action :set_so
def index
if logged_in?(:site_admin)
#request = Request.all
elsif logged_in?(:itp_user)
#request = Request.pending.requests_by current_user
else
#request = Request.pending.so_user_request current_user.service_orders
end
end
def new
#request = Request.new
end
def create
#request = current_user.requests.new(request_params)
authorize #request
respond_to do |format|
if #request.save
(#service_order.users.uniq - [current_user]).each do |user|
Notification.create(recipient: user, actor: current_user, action: "posted", notifiable: #request)
end
format.html { redirect_to #service_order, notice: 'Your request has been sent' }
else
format.html { redirect_to #request, :flash => { :error => #request.errors.full_messages.join(', ') } }
end
end
end
def show
authorize #request
end
def edit
authorize #request
end
def update
authorize #request
if #request.update(request_params)
redirect_to requests_path, notice: 'Your request was created successfully'
else
render :edit
end
end
def destroy
authorize #request
#request.destroy
redirect_to requests_path, notice: 'Your request was deleted successfully'
end
private
def request_params
params.require(:request).permit(:available_date,
:message,
:charge_range,
:status,
:heading,
:service_order_id,
:user_id
)
end
def set_request
#request = Request.find(params[:id])
end
def old_request
Request.where('created_at <= :fifteen_days', fifteen_days: Time.now - 15.days).where(status: "pending").destroy_all
end
def set_so
#service_order = ServiceOrder.find(params[:service_order_id])
end
end
My routes.rb:
Rails.application.routes.draw do
resources :request_logs
namespace :admin do
resources :users
resources :issue_types
resources :requests
resources :service_orders
root to: "users#index"
end
resources :conversations do
resources :messages
end
resources :requests
devise_for :users, path: '', path_names: { sign_in: 'login', sign_out: 'logout', sign_up: 'register' }
resources :service_orders, except: [:show] do
member do
get :toggle_status
end
end
get 'user-landing', to: 'user_landing#index'
get 'service_order/:id', to: 'service_orders#show', as: 'service_order_show'
get 'contact', to: 'pages#contact'
root to: 'pages#home'
end
Request Form View:
<%= form_for :request, url: requests_path do |f| %>
<% if #request.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#request.errors.count, "error") %> prohibited this request from being sent:</h2>
<ul>
<% #request.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="form-group">
<h4>Subject:</h4>
<em><%= f.text_area :heading, class: "form-control" %></em>
</div>
<div class="form-group">
<h4>Message:</h4>
<em><%= f.text_area :message, class: "form-control" %></em>
</div>
<div class="form-group">
<h4>Issue Charge Range:</h4>
<em><%= f.number_field :charge_range, class: "form-control" %></em>
</div>
<div class="form-group">
<h4>Soonest Available Date:</h4>
<em><%= f.date_field :available_date, class: "form-control" %></em>
</div>
<%= f.hidden_field :user_id, :value => current_user.id %>
<%= f.hidden_field :service_order_id, :value => #service_orders.id %>
<div>
<%= f.submit 'Send Service Request', class: 'btn btn-primary btn-block' %>
</div>
<% end %>
To route to nested resources you should pass an array.
form_for( [#service_order, #request])
redirect_to([#service_order, #request])
# ... etc
This is equivalent to calling service_order_requests_path(service_order_id: #service_order.to_param). You can also use the shallow: true option to avoid nesting the member routes.

NoMethodError for new controller in Rails

Cities#new controller shows error involving cities_path, but I don't have it in any file nor in CitiesController. I checked all files, tried to restart the server but still nothing.
undefined method `cities_path' for #<#<Class:0x007f9e4c1cb348>:0x00000003836140>
Did you mean? city_path
CitiesController
class CitiesController < ApplicationController
def index
#cities = City.all
end
def show
find_city
end
def new
#city = City.new
end
def edit
find_city
end
def update
find_city
if #city.save
redirect_to city_path(#city)
else
render "edit"
end
end
def create
#city = City.new(city_params)
if #city.save
redirect_to index_path
else
render "new"
end
end
private
def find_city
#city = City.find(params[:id])
end
def city_params
params.require(:city).permit(:name, :icon_url)
end
end
Routes
get "/cities/new" => "cities#new", as: "new_city"
post "/index" => "cities#create"
get "/cities/:id" => "cities#show", as: "city"
get "/cities/:id/edit" => "cities#edit", as: "edit_city"
patch "/city/:id" => "cities#update"
Form (error is raised on first line)
<%= form_for #city do |f| %>
<% if #city.errors.any? %>
<div class="errors">
<ul>
<% city.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.label "Name:" %>
<%= f.text_field :name, class: "form-control" %>
<%= f.label "Icon:" %>
<%= f.text_field :icon_url, class: "form-control" %>
<%= f.submit "Pošalji" %>
<% end %>
When you use form_for #city, and #city is a new record, form_for will try to find a cities_path to POST the new attributes back to.
You should be using resources :cities in your routes file to automatically define the routes and their names. If you want to define a limited set of routes, you can use :only or :except:
resources :cities, only: %i(new create show edit update)
If you don't use resources, you either need to explicitly specify a path for your form_for call, or you need to provide a route named cities_path manually:
post "/index" => "cities#create", as: :cities
Note that index routes don't typically actually contain the word index, you should really just be posting to /cities, not /index.
post "/cities" => "cities#create", as: :cities

Rails 4 routing (or missing ID) error on my project & versions association

I'm having some real trouble here - I have a project model & controller and also a version model and controller. Users create versions of a project, and on the project profile, I have a link to the versions index page that should just show the versions for that particular project_id. the URL for that page should be "projects/[project_id]/versions"...but i'm receiving the error below:
Showing /Users/user/Documents/clones/collab/app/views/versions/index.html.erb where line #46 raised:
-------
undefined method `id' for nil:NilClass
Extracted source (around line #46):
<ul class="nav nav-pills">
<li class="active"><%= link_to "Current State", #project %></li>
<li>
<%= link_to "Version History", project_versions_path(#project.id) %>
</li>
<li><span class="badge pull-right">12</span>Collaborators</li>
<li><span class="badge pull-right">6</span>Issues</li>
-------
I'm wondering if i maybe structured the controllers incorrectly because technically its an index list of 'versions' for a particular project profile (instead of just a sitewide index of versions for all projects). I also realize i have some repetition with that nav-list on the show pages that could be moved to a partial... But i'm just trying to get the code to work for now...Thanks for any help in fixing this...
ROUTES.RB
resources :users
resources :sessions, only: [:new, :create, :destroy]
resources :projects do
resources :versions
end
# get "static_pages/home"
# get "static_pages/help"
# get "static_pages/about"
#The original routes above map to...
root 'static_pages#home'
match '/signup', to: 'users#new', via: 'get'
match '/signin', to: 'sessions#new', via: 'get'
match '/signout', to: 'sessions#destroy', via: 'delete'
match '/help', to: 'static_pages#help', via: 'get'
match '/about', to: 'static_pages#about', via: 'get'
match '/contact', to: 'static_pages#contact', via: 'get'
PROJECTS MODEL:
class Project < ActiveRecord::Base
has_many :users
has_many :versions, dependent: :destroy
validates :title, presence: true, length: { maximum: 100 }
validates :background, presence: true
validates :user_id, presence: true
default_scope -> { order('created_at DESC') }
end
PROJECTS CONTROLLER:
class ProjectsController < ApplicationController
before_filter :signed_in_user, only: [:create, :new, :edit, :update]
def new
#project = Project.new
end
def show
#project = Project.find(params[:id])
#user = User.where(:id => #project.user_id).first
end
def index
#projects = Project.paginate(page: params[:page])
end
def create
#project = current_user.projects.build(project_params)
if #project.save
flash[:success] = "Welcome to your new project."
redirect_to #project
else
render 'new'
end
end
def edit
end
def update
#project = Project.find(params[:id])
if #project.update_attributes(params[:project])
flash[:success] = "Project Created"
redirect_to #project
else
render 'edit'
end
end
def destroy
User.find(params[:id]).destroy
flash[:success] = "Project destroyed"
redirect_to users_path
end
private
def project_params
params.require(:project).permit(:title, :background)
end
end
PROJECTS SHOW (PROJECT PROFILE):
<% provide(:title, #project.title) %>
<div class="row-fluid">
<section class="no-pad col-md-9">
<div class="row-fluid">
<div class="no-pad col-md-10">
<h1><%= #project.title %></h1>
<span class="timestamp"><span class="glyphicon glyphicon-time"></span> Created <%= time_ago_in_words(#project.created_at) %> ago by <%= #project.user_id %></span>
<p><%= #project.background %></p>
</div>
<div class="col-md-2">
<%= link_to "#", :class => "pull-right" do %>
<%= image_tag("lock.png", alt: "private info") %>
<% end %><br clear="all">
<span class="timestamp pull-right">private</span>
</div>
</div><br clear="all">
<div class="row-fluid">
<ul class="nav nav-pills">
<li class="active"><%= link_to "Current State", #project %></li>
<li>
<%= link_to "Version History", project_versions_path(#project.id) %>
</li>
<li><span class="badge pull-right">12</span>Collaborators</li>
<li><span class="badge pull-right">6</span>Issues</li>
<li><span class="badge pull-right"></span>Project Buzz</li>
</ul><br clear="all">
</div>
<div class="row-fluid">
<div class="no-pad col-md-6">
<h4>File Attachment</h4>
<div class="bs-callout bs-callout-success">
<%= link_to "download" do %>
<%= image_tag("icon.png", alt: "file") %>
<% end %><br clear="all">
</div>
</div>
<!-- LATEST PROJECT VERSIONS -->
<div class="col-md-6">
<h4>Latest Versions</h4>
<% #project.versions.first(5).each do |version| %>
<%= link_to project_version_path(#project, version) do %>
<h6><%= version.title %></h6>
<% end %>
<% end %>
</div>
<!-- END OF PROJECT VERSIONS -->
</div>
VERSIONS MODEL:
class Version < ActiveRecord::Base
belongs_to :project
validates :title, presence: true, length: { maximum: 140 }
default_scope -> { order('created_at DESC') }
end
VERSIONS CONTROLLER:
class VersionsController < ApplicationController
def new
#version = Version.new
end
def show
#project = Project.find(params[:project_id])
#version = Version.find(params[:id])
end
def index
#versions = Version.paginate(page: params[:page])
end
def create
#project = Project.find(params[:project_id])
#version = #project.versions.create(version_params)
if #version.save
flash[:success] = "You've successfully added a version to this branch..."
redirect_to project_path(#project)
else
render 'new'
end
end
def edit
end
def update
end
def destroy
end
private
def version_params
params.require(:version).permit(:title)
end
end
VERSIONS INDEX (the Url would be "projects/[project_id]/versions"
<% provide(:title, #versions ) %>
<div class="row-fluid">
<section class="no-pad col-md-9">
<div class="row-fluid">
<ul class="nav nav-pills">
<li><%= link_to "Current State", #project %></li>
<li class="active">
<%= link_to "Version History", project_versions_path(#project.id) %>
</li>
<li><span class="badge pull-right">12</span>Collaborators</li>
<li><span class="badge pull-right">6</span>Issues</li>
<li><span class="badge pull-right"></span>Project Buzz</li>
</ul><br clear="all">
</div>
<h4>Version History</h4>
<%= will_paginate %>
<ul class="versions">
<% #versions.each do |version| %>
<%= render version %>
<% end %>
</ul>
<!-- CAN REFACTOR TO BELOW FOR CLEANER CODE
<ul class="versions">
<%= render #versions %>
</ul>
-->
<%= will_paginate %>
Your view at app/views/versions/index.html.erb is looking for #project.id, but #project isn't defined.
You need to set a value for #project in your index action. I'd recommend refactoring it into a before_action call to tidy up your controller a little:
class VersionsController < ApplicationController
# Also add other actions that need for #project to be set (or leave out the `only`
# option for ALL actions, which almost certainly applies to your situation with a nested
# resource like this)
before_action :find_project, only: [:index, :show, :create]
def show
#version = Version.find(params[:id])
end
def index
#versions = Version.paginate(page: params[:page])
end
def create
#version = #project.versions.create(version_params)
if #version.save
flash[:success] = "You've successfully added a version to this branch..."
redirect_to project_path(#project)
else
render 'new'
end
end
private
def find_project
#project = Project.find(params[:project_id])
end
#...
end

How can I add a related record whilst on its parents edit page?

I have a table of venues and offers. Each venue can have have many offers.
I would like to be able to add the offers to the venues from the venues edit page. So far I have this (code below) but its giving a "NoMethodError in Venues#edit, undefined method `model_name' for NilClass:Class" error.
venues edit page
(the div id="tabs-3" is a container in an accordion)
<div id="tabs-3">
<%= form_for [#venue, #offer] do |f| %>
<h2 class="venue_show_orange">Offers</h2>
<%= f.fields_for :offers do |offer| %>
<div class="add_offer">
<%= offer.text_field :title %><br>
</div>
<div class="button"><%= submit_tag %></div>
<% end %>
<% end %>
</div>
offers controller
class OffersController < ApplicationController
def new
#offer = Offer.new
end
def create
#offer = #venue.offers.create!(params[:offer])
#offer.venue = #venue
if #offer.save
flash[:notice] = 'Offer added'
redirect_to offers_path
else
render :action => :new
end
end
def edit
#offer = Offer.find(params[:id])
end
def update
#offer = Offer.find(params[:id])
#offer.attributes = params[:offer]
if #offer.save!
flash[:notice] = 'Offer updated successfully'
redirect_to offers_path(#offer)
end
end
end
venues controller
(nothing offer related in here - is this where I'm going wrong?)
class VenuesController < ApplicationController
protect_from_forgery :only => [:update, :delete, :create]
load_and_authorize_resource
def new
#venue = Venue.new
5.times { #venue.venuephotos.build }
end
def create
#venue = Venue.new params[:venue]
if #venue.save
flash[:notice] = 'Venue added'
redirect_to venues_path
else
render :action => :new
end
end
def edit
#venue = Venue.find(params[:id])
5.times { #venue.venuephotos.build }
end
def update
#venue = Venue.find(params[:id])
#venue.attributes = params[:venue]
if #venue.save!
flash[:notice] = 'Venue updated successfully'
redirect_to :back
end
end
end
Any help is much appreciated thanks very much!
edit
venues edit page
<div id="tabs-3">
<%= form_for #venue do |f| %>
<div class="edit_venue_details">
<h2 class="venue_show_orange">Offers</h2>
<%= render :partial => 'offers/offer', :collection => #venue.offers %>
<div class="clearall"></div>
<h2 class="edit_venue_sub_header">Add a new offer</h2>
<%= f.fields_for :offers do |offer| %>
<% if offer.object.new_record? %>
<p class="edit_venue">title: <br>
<%= offer.text_field :title, :class => "edit_venue_input" %></p>
<% end %>
<% end %>
</div>
<button class="submit_button" type="submit"> Save changes</button>
<% end %>
</div>
whats being displayed
however if I add a new offer, that will display correctly:
Some remarks:
1) Replace:
<%= form_for [#venue, #offer] do |f| %>
with:
<%= form_for #venue do |f| %>
Because offers data will be updated through the related venue, only one controller action will handle the form.
2) If you want to add some unexisting offers in this form, you shoud instantiate them the way you did with venuephotos
3) Show your Venue model. You should have at least:
accepts_nested_attributes_for :offers
Fixed with:
<%= f.fields_for :offers, #venue.offers.build do |offer| %>

Resources