0

In my app I have a view called profiles. On this view the user can update your albums and the photos of those albums.

A User has many Albums. And a Album has many Photos.

Im creating a form inside my profile view to save a album. Like this:

#routes.rb
  get '/profile/edit/profile_albums', to: 'profiles#edit_profile_albums'


#/view/profile/edit/profile_albums.html.erb


<%= form_for album do |f| %>
    <div class="dialog dialog-centered" id=<%= album.id %> style="display: block;">
      <div class="dialog-container dialog-wide">
        <div class="dialog-content panel">
          <div class="form-group bottom-7">
            <label for="">Album Name</label>
            <input type="text" id="" value=<%= album.name %> placeholder="Add Album Name">
          </div>
          <div class="edit-photo-album bottom-5">
          <% album.photos.each do |photo| %>
           <span class="edit-photo">
              <img src="<%= asset_path ix_refile_image_url(photo, :media, fit: 'fill', bg: '0fff') %>" class="photo-preview">
                <a href="" title="Remove" class="remove-item">Remove</a>
           </span>
          <% end %>
                <span class="btn btn-default btn-file">
                        <i ></i> Upload Photos 
                        <%= f.attachment_field :photos_media, multiple: true, direct: true, presigned: true %>
                    </span>

          </div><!-- end photo album -->
          <p>
          <div class="actions">
            <%= f.submit 'Save Album', class: 'btn btn-lg btn-solid-red btn-margin-right' %>
          </div>
          <button type="button" class="btn btn-lg btn-outline-green dialog-close">Cancel</button>
          </p>
        </div><!-- end dialog content -->
      </div><!-- end dialog container -->
    </div>
<% end %>

When I pressing the button save:

 <%= f.submit 'Save Album', class: 'btn btn-lg btn-solid-red btn-margin-right' %>

I get this message:

Routing Error
No route matches [PATCH] "/profile/edit/albums"

Someone can help me?

Thanks

1
  • 1
    Why do you need a URL like this: '/profile/edit/profile_albums', and not '/profile/:id/edit/profile_albums'? Commented Sep 7, 2018 at 6:12

2 Answers 2

3

I think you need to specify the url in the form_for.

First using rake routes, check for the route where this form should be sent to, and then modify your form for to be something like:

<%= form_for album, url: edit_profile_albums_path do |f| %>

Just replace edit_profile_albums with the path you will get when you run rake routes

Sign up to request clarification or add additional context in comments.

Comments

1

As the error suggests, you need to add the proper route for the form to work. In this case, it's probably resources :albums in routes.rb. I recommend going through this guide (easy to read): https://guides.rubyonrails.org/routing.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.