i have a form with simple_form gem. if i digit the url in the browser with the anchor tag it works:
localhost:3000/contacts/#new_contact #show me the correct form in the page
this is my controller:
class ContactsController < ApplicationController
def index
@message = Contact.new()
end
def create
@message = Contact.new(msg_params)
@message.request = request
if @message.deliver
redirect_to contacts_path , flash: { success: 'Ok' }
else
render action: :index #how can i render the new_contact anchor??
end
rescue ScriptError
redirect_to contacts_path , flash: { error: 'spam' }
end
private
def msg_params
params.require(:contact).permit(:name,:email,:message,:spam)
end
end
this is my form:
<%= simple_form_for @message, defaults: { label: false} do |f| %>
<%= f.input :name %>
<%= f.input :email %>
<%= f.input :message, :as => :text,input_html: { rows: 7 } %>
<div class="hidden">
<%= f.input :spam, :hint => 'Leave this field blank!' %>
</div>
<%= f.button :submit, 'Send', class: 'btn-block btn-success btn-lg' %>
<% end %>
how can i show the new_contact anchor with the render method?
You can't use render
to modify the anchor tag. In fact, render
has nothing at all to do with the URI.
You can use existing links to link to "/url#anchor", redirect there, or use javascript to achieve the same effect.
You might also need to add :id => 'anchor'
if the anchor itself isn't setup on the form.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With