What should I do if Rails returns a message from the controller without changing the display?
We have created a screen with the following specifications:
=>When displaying messages, the contents of the list screen should be in the state before pressing the Next button
Currently, the code is as follows. I am using Rails 4.1.5.
#controller
def index
@items=items
end
def show
@select_no=params[:select_no]
# transition pretreatment
rescue HogeError=>e
flash.now.alert="Error Occurred"
render —index
end
definitions
# Items creation process; non-ActiveRecord.
end
# view index.erb
<%=render "error_message_area" %>
<%[email protected] event?%>
<%=form_tag(item_path, method::get)do%>
<table class="table" id="item_select">
<thead>
<tr>
<th>Select </th>
<th>No>/th>
<th>Name</th>
</tr>
</thead>
<tbody>
<%@items.each_with_index do|item,index|%>
<tr>
<td class="ctrl">%=radio_button_tag("select_no", item[:no], index==0)%>/td>
<td class="no">%=item[:no]%>/td>
<td class="name">%=item[:name]%>/td>
</tr>
<%end%>
</tbody>
</table>
<div>
<%=button_tag type:"submit" do%>
next
<%end%>
</div>
<%end%>
<%end%>
Currently, if an error occurs, the list of items will disappear.
If you use @select_no
to select the radio button, you can use
#show
#show
(call #items
)I came up with the idea that none of them fit well. Proposition B is dynamic in the list and may differ from before pressing the button.
Is there any good way?
ruby ruby-on-rails
I don't have enough credit, so I'll give you a different answer.
If AJAX handles it, there is also a way called RJS.
button in pressed events without submitting
Disable (or disable) all items in the form
Skip the form.serialized data and
If the processing results are normal, you can return the code to submit.
Should I display a message and enable it if it fails?
It's a generalization because it's impossible to share the sensuous story of "it doesn't fit well" with this much information.
Regarding the solution that the content should not be changed due to the screen transition,
either of the .
2. You can either use Ajax in C. or open a separate window in window.open, and you can use window.opener to handle the original window.
Since you did not set @items in the show action, the <%[email protected] event?%> decision is false and the display is empty.
© 2024 OneMinuteCode. All rights reserved.