Skip to content

Instantly share code, notes, and snippets.

@puneetpandey
Created August 12, 2015 09:19
Show Gist options
  • Save puneetpandey/f0a4038b520ceab57d6c to your computer and use it in GitHub Desktop.
Save puneetpandey/f0a4038b520ceab57d6c to your computer and use it in GitHub Desktop.
class ActsController < ActionController::Base
before_filter :get_user
def new
@act = @user.acts.new
end
def create
@act = @user.acts.new params[:act]
respond_to do | format |
if @act.save
flash[:notice] = "Act uploaded successdfully"
format.html { redirect_to @act }
else
flash[:error] = "Error occurred. Please try again."
format.html { render action: 'new' }
end
end
end
private
def get_user
@user = User.find session[:user_id]
end
end
class Act < ActiveRecord::Base
attr_accessible :file
attr_accessor :file
before_validation :ensure_file_is_valid?
protected
def ensure_file_is_valid?
if file.nil?
errors.add(:base, "")
end
end
end
# _form.html.erb
<%= form_for([@user, @act]) do | f | %>
<%= f.file_field :file %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment