I have an model called Purchase.rb. each purchase is created through a form as follows.
<%= form_for(@purchase) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="field">
<%= f.text_field :content, placeholder: "Describe something you are interested in buying.", :maxlength=>"254" %>
<%= f.file_field :photo %>
</div>
<%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>
when they are created they are displayed with a partial stored in app/views/purchases/_purchase.html.erb. To add photos, I have put
<%= form_for(@purchase) do |f| %>
<%= f.file_field :photo %>
<%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>
in the purchase itself. I am using paperclip. So the idea is that people can click on a field that is part of the purchase and add a photo to the view.
the error I get says
Missing template purchases/users#show, application/users#show with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/home/alex/rails_projects/tradespring!/app/views"
I want it to look at app/views/users#show, not app/views/purchases/users#show
edit:
here is the show action of the userscontroller:
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
@purchases= @user.purchases
@sales= @user.sales
@purchase=Purchase.new
@sale=Sale.new
end
and here is the routes.rb
Tradespring::Application.routes.draw do
resources :users do
resources :pcomments
resources :scomments
end
resources :sessions, only: [:new, :create, :destroy]
resources :purchases do
resources :pcomments
end
resources :sales do
resources :scomments
end
get "static_pages/home"
get "static_pages/about"
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/about', to: 'static_pages#about'
match '/signout', to: 'sessions#destroy', via: :delete
root to: 'static_pages#home'
finally, here is the what I want to happen when I submit the picture form. Im not 100% sure it should be under update.
class PurchasesController < ApplicationController
def update
@purchase = Purchase.find(params[:id])
if @purchase.update_attributes(params[:purchase])
flash[:success] = "Picture added"
redirect_to :back
else
render 'users/show'
end
end
also here is the app/views/user/show.html.erb
<% provide(:title, @user.name) %>
<p>
<%= mail_to(@user.email, name="email this user", :encode => "javascript") %>
</p>
<div id="purchases">
<%= form_for(@purchase) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="field">
<%= f.text_field :content, placeholder: "Describe something you are interested in buying.", :maxlength=>"254" %>
<%= f.file_field :photo %>
<p1> Note: There is a 254 character limit. Be sure to include useful information such as product specifications, how much you are willing to pay, and shipping info (where you live, if you want to pick it up locally, ect.). Further detail is best left to email.</p1>
</div>
<%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>
<% if @user.purchases.any? %>
<h3>Purchases (<%= @user.purchases.count %>)</h3>
<ol class="purchases">
<%= render @purchases %>
</ol>
<% end %>
</div>
<div id="sales">
<%= form_for(@sale) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="field">
<%= f.text_field :content, placeholder: "Describe something you are interested in selling.", :maxlength=>"254" %>
<p1> Note: There is a 254 character limit. Be sure to include useful information such as product specifications, price, payment methods accepted, and shipping info (where you live, if you are willing to ship it, ect.). Further detail is best left to email. </p1>
</div>
<%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>
<% if @user.sales.any? %>
<h3>Sales (<%= @user.sales.count %>)</h3>
<ol class="sales">
<%= render @sales %>
</ol>
<% end %>
</div>
The issue was that I needed to define the action of the second form for. I guess by default, the form for assumes that you want the create action. In this case I wanted it to use the update action so I needed to change it to <%= form_for((@purchase), :url => { :action => “update” }) do |f| %>