I am a super newbie in rails. Studied in a few weeks. Sorry, my idiocy. I can not get the file that I selected to download.
I am using Rails 4.0.0.
I am working on my first application, and I started with a rail guide for the blog application. I took this and ran with it and create something else (bug tracking system), just trying to learn the ropes.
So, I have my form:
<%= form_for @post do |f| %>
and I added in the file_field field. The displayed part in the view looks and works well, as the file selection goes.
<%= f.label :attachment %> <%= f.file_field :attachment %>
I pulled it out of the rails of 4 FYI guides. So my controller looks like this:
class PostsController < ApplicationController def new @post = Post.new end def create @post = Post.new(params[:post].permit(:title, :text, :user, :screen)) if @post.save redirect_to posts_path else render 'new' end end def show @post = Post.find(params[:id]) end def index @posts = Post.all end def edit @post = Post.find(params[:id]) end def update @post = Post.find(params[:id]) if @post.update(params[:post].permit(:title, :text, :user, :screen)) redirect_to posts_path else render 'edit' end end def destroy @post = Post.find(params[:id]) @post.destroy redirect_to posts_path end def upload uploaded_io = params[:post][:attachment] File.open(Rails.root.join('public', 'uploads', uploaded_io.original_filename), 'w') do |file| file.write(uploaded_io.read) end end private def post_params params.require(:post).permit(:title, :text, :user, :screen, :attachment) end end
The new part is loading here. Everything else works fine with writing / reading from the database and displaying. When the view is displayed, I make text entries, attach the file and click submit. Everything is written to the database and displayed by index, but the file I tried to connect is not written to ~ / bugs / public / uploads /
Thanks in advance for your help.