My web app follows the structure as described in previous questions here and here.
See the picture below of the interface.
What I want is, when the user edits/updates verification through the switch
icon (submit button automatically), also described here, the div
containing the verify/patch icon should reload/refresh to update that a translation is verified.
I could possibly have all these elements in one field, but only moderator: true
users get to create
and only moderators who moderated specific translations can edit and update
the review
.
What I tried is having
# entries/index.html.erb
<% @entries.each do |entry| %>
...
<span id="show-review-<%= entry.id %>">
<%= render 'reviews/show', entry: entry %>
</span>
...
<% if current_user.moderator %> # and other conditions
<div id="edit-review-form-<%= entry.id %>">
<%= render 'reviews/edit', entry: entry %>
</div>
<% end %>
...
<% end %>
# reviews/_show.html.erb
# Simply if the review exists and if its true
<% if entry.review and entry.review.verified == true %>
# blue verify icon
<% else %>
# gray vefify icon
<% end %>
# reviews/_edit.html.erb
<%= form_for([entry, entry.review], remote: true, :authenticity_token => true) do |f| %>
...
<% end %>
# reviews/edit.js.erb
$('show-review-<%= entry.id %>')[0].html("<%=j render 'reviews/show', entry: entry %>")
Problem: When I submit the edit form, and update
action in the controller is executed, I would like to reload the section of show
. If I have my controller in this way...
def update
if @entry.review.update!(review_params)
respond_to do |format|
format.html { render :partial => "reviews/show", :layout => false }
format.js { render :template => "reviews/edit", :layout => false }
end
end
end
Having this, on update
, my site instead redirects to a reviews URL http://localhost:3000/entries/entry:id/reviews/review:id
This is a nested, kinda, model. Why does is redirect to show
when it's just a partial?
# rake routes
entry_reviews GET /entries/:entry_id/reviews(.:format) reviews#index
POST /entries/:entry_id/reviews(.:format) reviews#create
new_entry_review GET /entries/:entry_id/reviews/new(.:format) reviews#new
edit_entry_review GET /entries/:entry_id/reviews/:id/edit(.:format) reviews#edit
entry_review GET /entries/:entry_id/reviews/:id(.:format) reviews#show