0
votes

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:

enter image description here

5
Not sure what you mean by click on the "link_to". I suppose you do not mean that there is a link on the rendered page that says "link_to".sawa
can you show output of rake routes | grep albums by running it on console on project directory?Anand
where does page redirects on click on this link? do you get any error?Anand
Nothing happens. I inspect the code, and its like this: <a class="btn-upload trigger-file-upload" href="/albums/new"></a>. If I click it on directly on the inspector, it works. Maybe some JS issue?Fernando Maymone
Your question didn't understand please ask clearlyGiridharan

5 Answers

1
votes

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.

0
votes

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
0
votes

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.

0
votes

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;
  });
0
votes

Try like this

 <span class="file-upload">
<a class="btn-upload trigger-file-upload" herf=" <%=  new_album_path%>"</a>
 </span>