Reputation: 355
I have one page with a button to create a new album of photos on my app like this:
<span class="file-upload">
<%= link_to '', new_album_path, class: "btn-upload trigger-file-upload"%>
</span>
My routes.rb is like this:
resources :albums do
resources :photos
end
If I click directly on my page like this, it works:
https://localhost:3000/albums/new
Why the link generated by <%= link_to '', new_album_path, class: "btn-upload trigger-file-upload"%> doesnt works? I click on it, and the page isnt redirected
Edited: My rake routes:
Upvotes: 0
Views: 61
Reputation: 568
Try like this
<span class="file-upload">
<a class="btn-upload trigger-file-upload" herf=" <%= new_album_path%>"</a>
</span>
Upvotes: 0
Reputation: 355
It was a problem on my javascript, that makes the click button being overrided
$('.trigger-file-upload').click(function(event){
form = $(this).parents('.file-upload').parent();
field = $(this).parents('.file-upload').find('input[type="file"]');
field.trigger('click');
return false;
});
Upvotes: 0
Reputation: 1502
I think everything is good except one thing text for anchor, so when you click on that text and it will open https://localhost:3000/albums/new
.
<span class="file-upload">
<%= link_to 'Create New Album',
new_album_path, class: "btn-upload trigger-file-upload" %>
</span>
I hope this will help you.
Upvotes: 0
Reputation: 6085
More of a "teach how to fish" but to determine what routes are available in your application and the cooresponding paths you should run
rails routes | grep album
That will show you all of the possible named routes along with their path and associated controller. Yours is most likely named new_album_photo_path
for getting a link to upload a new image. Always consult the rails routes though when you have a question.
Upvotes: 1
Reputation: 948
if you want to use new_album_path, you need to have resources :photos in your routes.rb file. So you need to only keep:
resources :photos
instead of
resources :albums do
resources :photos
end
Upvotes: 0