Last active
January 2, 2016 15:09
-
-
Save redrory/8321224 to your computer and use it in GitHub Desktop.
Currently, when you find an event (if - successful ). It loads my modal via index.js.erb
That works fine, however I want to load a different set of modals if an event is not found (else).
However, on the else condition; it doesn't load the index.js.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def index | |
if @event = Event.find_by_event_code(params[:checkin]) | |
flash[:success] = "You have found your event" | |
elsif @event = Event.find_by_speaker_code(params[:checkin]) | |
flash[:success] = "Welcome Co-Speaker. You have found your event" | |
else | |
flash[:error] = "No event by that event code" | |
end | |
respond_to do |format| | |
format.html { redirect_to @event } | |
format.js | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#checkin-popup").remove(); | |
$("#checkin-confirm-popup").html("<%= escape_javascript(render("/events/index.html.erb")) %>") | |
$('#checkin-confirm-popup').modal('show'); |
And a little bit of refactor:
def index
@event = Event.find_by_event_code(params[:checkin]) || Event.find_by_speaker_code(params[:checkin])
respond_to do |format|
if @event.event_code == params[:checkin]
format.html { redirect_to @event, success: "You have found your event" }
format.js
elsif @event.speaker_code == params[:checkin]
format.html { redirect_to @event, success: "Welcome Co-Speaker. You have found your event" }
format.js
else
format.html { redirect_to @event, error: "No event by that event code" }
format.js
end
end
end
See revision 2
You're missing here the e
https://gist.github.com/redrory/8321224#file-button-html-erb-L3
<div class="talknumber"><%= e.input :checkin, input_html: { value: params[:search] }%></div>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can force the rendering by moving the if clause inside the respond_to block, look: