ive been trying to render a picture from carrierwave. i believe it is uploaded correctly because when i view the page source, i see
<img alt="Photo_44" src="/uploads/user/image/59/Photo_44.jpg" />
however by clicking on that src url, i get
No route matches [GET] "/uploads/user/image/59/Photo_44.jpg"
im using the default settings for carrierwave. the image does correctly get uploaded to my image column in my users table and locally, the path
sasha/Desktop/rails_projects/myproject/public/uploads/user/image/59/Photo_44.jpg
exists as well. however it won't display correctly. ive been following the railscasts
http://railscasts.com/episodes/253-carrierwave-file-uploads?autoplay=true
and reading
https://github.com/jnicklas/carrierwave
but i cant seem to figure out what is wrong. where i upload the image is here
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name),
:html => { :method => :put, :multipart => true }) do |f| %>
<%= devise_error_messages! %>
<%= render '/shared/fields', object: f.object, f: f %>
<%= f.submit "Save changes", :class => "btn btn-large btn-primary", :style =>"display:block;" %>
<div class="edit_avatar" >
<%= f.file_field :image %>
</div>
<% end %>
and im trying to render it by...
<%= image_tag #user.image_url.to_s %>
what am i doing wrong?
help would be appreciated = )
thank you
Try set config.serve_static_assets = true if you haven't yet, should help.
Related
I am using Paperclip to manage files.
File upload works perfectly in development, but in production environment file_field tag is not choosing anything.
Form:
<div class="change-avatar">
<%= form_for #user, :html => { multipart: true } do |f| %>
<%= f.file_field :avatar, id: "avatarInput" %>
<a id="avatarInput_alt">Change avatar</a>
<%= f.submit id: "submitAvatar"%>
<% end %>
</div>
The dialog is being showed when I click on the 'Choose file' button, but after I choose a file it still shows no file selected.
When I call document.getElementById("avatarInput").files the output is FileList {length: 0, item: function}.
Does anyone know what is wrong?
Thank you in advance
I have the follwoing form in my view :
I have an instance variable #selected_folder somewhere above in this view
<%= form_for :workflow_selection, :remote => true, :method => "get", :url => {:action => "final_submission"} do |f| %>
<p> Check the workflows needed and then click on the button with folder name</p>
<% #workflow_map[#selected_folder].each do |i| %>
<p><%= f.check_box(i)%> <%= f.label(i, i)%><br /><p>
<% end %>
<br />
<p><%= f.submit #selected_folder%></p>
<% end %>
I want to label the submit button as just 'submit' and should still be able to pass the #selected_folder instance variable to the final_submission action mentioned in the form_for tag
I tried various option like
<%= form_for :workflow_selection, :remote => true, :method => "get", :selected_folder => #selected_folder
:url => {:action => "final_submission"} do |f| %>
i tried to create a select drop down and hide it from view but still trying it to pass once the submit button is clicked.
and some more options..
None of them worked
Please help.
If you want to pass #selected_folder along in the form submission, you can add a hidden_field_tag.
As per Rails documentation:
hidden_field_tag(name, value = nil, options = {})
So in your case
<%= hidden_field_tag 'selected_folder', #selected_folder %>
in the workflow_selection, selected_folder will be present in the form hash.
I'm attempting to use PaperClip and have been following the quick start found on their GitHub page.
I've got the gem install, model & controller set up, and in the view I have:
<% form_for #account, :html => { :multipart => true } do |f| %>
<%= f.file_field :image %>
<% end %>
But nothing displays when the page renders. I've stripped out all CSS to ensure that isn't an issue, but still not luck. Any thoughts on why the file picker isn't displaying? Thanks.
Not sure what version of Rails you are using but I think you forgot the equals sign in the form helper, try:
<%= form_for #account, :html => { :multipart => true } do |f| %>
<%= f.file_field :image %>
<% end %>
I am new to rails and just wrote a pretty complex for that updates the child elements of a video model I created.
The problem is, when I click the submit buttons it should go to the update function in the controller but instead it does nothing.
Here is my code:
<%= form_for :video, :url => video_path(#video), :html => { :method => 'put' } do |f| %>
.
.
.
<p><%= submit_tag "Update video" %></p>
<% end %>
What am I doing wrong?
:method => 'put' is not :html option so try this:
<%= form_for :video, :url => video_path(#video), :method => 'put' do |f| %>
.
.
.
<p><%= submit_tag "Update video" %></p>
<% end %>
OK, I found out what the problem was. In my routes file the rout for the video path was directing video/:id to a different location. after commenting that line it got to the update function.
I have the below form in my view:
<% form_for(#filedata, :url=>{ :controller=>"filedatas", :action=>"create"}, :multipart => true) do |f| %>
<label>Select File</label> : <%#= f.file_field :file %>
<%= file_field_tag 'uploadedFile' %>
<%= f.submit 'Upload' %>
</p>
<% end %>
I've commented out the f.file_field but I have tested on both and both give me the same problem. They just return the name of the file and I get a string. methods like .path and .original_filename cause an error.
In my list of parameters I get:
"uploadedFile"=>"test"
(the name of my file is test.txt)
Anyone have any suggestions?
Sorry, I may have misunderstood your original question. It looks like you have an error in your form_for call. It should be:
<% form_for(#filedata, :url=>{ :controller=>"filedatas", :action=>"create"}, :html => {:multipart => true}) do |f| %>
You were missing the ":html =>{}" part. Also, you can shorten it down like this:
<%= form_for #filedata, :html => {:multipart => true} do |f| %>
This is happening because the contents of the file aren't stored in the attribute like other fields. File contents are stored in the POST data, and have to be retrieved. Extra steps are required.
This article explains one way to do it manually. But a better approach is to use a plugin like thoughtbot's paperclip to handle this for you.