forms - How do I get my image upload to work on rails? -


i have form saves image title, description , url uploads onto project. added upload option form , i'm confused how can save onto server , show after upload. - , isn't priority - there way assign upload url users can share?

my form: (f.file_field picture i'm using upload image)

<h1>add picture</h1> <%= link_to "back pictures", pictures_url %> <%= form_for @picture |f| %>   <p>     <%= f.label :artist %><br>     <%= f.text_field :artist %>   </p>   <p>     <%= f.label :title %><br>     <%= f.text_field :title %>   </p>     <p>    <%= f.file_field :picture %>   </p>   <p>     <%= f.label :url %><br>     <%= f.text_field :url %>   </p>   <p>     <%= f.submit "save" %>   </p> <% end %>  </center> 

controller:

class picturescontroller < applicationcontroller    def index     @pictures = picture.all   end    def new     @picture = picture.new   end    def create     # make new picture picture_params returns (which method we're calling)     @picture = picture.new(picture_params)     if @picture.save       # if save picture successful, go index.html.erb       redirect_to pictures_url     else       # otherwise render view associated action :new (i.e. new.html.erb)       render :new     end   end    def show     @picture = picture.find(params[:id])   end    def edit     @picture = picture.find(params[:id])   end    def update     @picture = picture.find(params[:id])      if @picture.update_attributes(picture_params)       redirect_to "/pictures/#{@picture.id}"     else       render :edit     end   end    def destroy     @picture = picture.find(params[:id])     @picture.destroy     redirect_to pictures_url   end    private   def picture_params     params.require(:picture).permit(:artist, :title, :url)   end  end 

thanks help! want keep minimal possible , don't want opt gem.

your :picture isn't permitted in picture_params. permit saved in db

def picture_params    params.require(:picture).permit(:artist, :title, :url, :picture) end 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -