I have this code in my view
<form>
<%= form_tag(portefeuillemodele_path, :remote => true) do %>
<%= label_tag(:date, "The selected date is:") %>
<%= text_field_tag(:date) %>
<%= submit_tag("OK") %>
<% end %>
</form>
And this in my controller
def index
@portefeuillemodeles = Portefeuillemodele.all
@date = params[:date]
respond_to do |format|
format.html # index.html.erb
format.json { render json: @portefeuillemodeles }
end
end
When I press the submit button, it doesn't do anything. And I have ajax gem installed, what do I need to just save the submitted value , so I can use it in my view ?
Looking at your code
<form> // you don't need this tag form_tag will create those tags for you
<%= form_tag(portefeuillemodele_path, :remote => true) do %>
<%= label_tag(:date, "The selected date is:") %>
<%= text_field_tag(:date) %>
<%= submit_tag %>
<% end %>
</form>
Secondly when you are using ajax you need js format in your controller
def index
@portefeuillemodeles = Portefeuillemodele.all
@date = params[:date] # this will give you access to your date but you need to check your params to be sure
respond_to do |format|
format.html # index.html.erb
format.js{} # ajax will call this format not html or json
format.json { render json: @portefeuillemodeles }
end
end
This will allow rails to look for a file named index.js.erb where you can manipulate your DOM elements by js. For details refer to Working with Javascript in Rails
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments