I hope you will help me with a little problem.
I have some code in ror controller:
def create
@email = Email.new(params[:email])
respond_to do |format|
if @email.save
format.html { redirect_to root_path }
format.json { render json: @email, status: :created, location: @email }
else
format.html { render action: "new" }
format.json { render json: @email.errors, status: :unprocessable_entity }
end
end
end
And if email saved,
if @email.save
I want div to be showed in HTML file
<div id="notice">OK</div>
with this javascript
document.getElementById("notice").style.display = 'block';
But I don't know where should I put js file and how I should call it from controller.
Thanks.
Rails will be looking for the 'new' template to return to the user when the render action is called. The specified action is used to determine which view to render.
You will want to place the JavaScript in this template. Once the user posts to your controller the 'new' template will be returned to their browser and your JavaScript can be executed client side.
For more information please see: http://guides.rubyonrails.org/layouts_and_rendering.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.