page inbetween search results and results - ruby-on-rails

So i have this page called ticket amount which has a bunch of buttons on it.
Wha im wanting is for the user to click the button on the row of the search results and be taken to that page. The user will then click on the amount of tickets they want and be taken to the page that matches the id from the from the row the button was on.
Basically at the moment its going
Search results >>>>> results
And i want
Search results >>>>> ticket amount >>>>> results
I've currently got the first one set up like this
<%= link_to 'Compare', event_path(event.id), class: "btn btn-info" %>
How would i go about making it different? Basically i'm wanting to use the amount of tickets the user selects in the view. So probably best to change the url from this
/events/idnumber
to
events/idnumber/tickets_required=4
Any ideas how to do this?
At the moment the ticket_amount.html only has basic bootstrap buttons inside

What you need to do is to send the params in a redirect_to.
What I would do is a small form for let the user select the tickets_required, the form will point to an action in the controller, within that action I would add a redirect to the search results url sending the param:
#Within your controller action once the user selects the tickets_required
redirect_to event_path(event, tickets_required: params[:tickets_required])
Redirect to the search results url or event_path or whatever, and send the tickets_required param in the url using the param[:ticket_required] coming from the form submission
Take a look to this thread that will guide you about how to send the params in the redirect_to

Related

page with params between search and show page

So i have this page that shows a result of events with a button that takes you to the eventid (which has a list of prices)
What im wanting to do is one of my api's is only showing all tickets available (how considerate). So i'm having to adjust to them.
What im wanting (and have made but not put in yet) is to have a page inbetween the search results and the show.html.erb
This page has a bunch of buttons on it, Asking how many tickets your looking for. e.g. 2 tickets for the event.
Now what im wondering is how i can go about this?
Currently the button is linked up like this (on the search results page)
<%= link_to 'Compare', event_path(event.id), class: "btn btn-info" %>
However what im going to want to do is have this button link off to a page called ticket_numbers.html.erb This will sit inbetween these two pages and when a user clicks said button on that page it shall allow me to use the number in the view and related jquery files.
Any help would be great!!
Thanks
Sam
You need to define a route for this new page:
match '/ticket_numbers' => 'controllerName#ticket_numbers'
And to create the file ticket_numbers.html.erb on the corresponding view folder.After this your new page will work.
If you need any controller logic define a method ticket_numbers on the corresponding controller:
class controllerNameController < ApplicationController
def ticket_numbers
end
end

How can I embed a form (scaffold) into a home page using ROR?

I have created a scaffold called TRADER and gave it the entries
fname:string
lname:string
twitteruser:string
email:string
I want the form visible on the index page for the app user to submit their entry. Upon submission, I want a pop up box to appear saying " Thank you for your submission."
I do not want to show the user what they just submitted, and the DB that holds all the submissions is accessed with authentication only available to me.
Currently the blank form is located in localhost:3000/traders/new
then after submission, the app displays the submitted information.
First, How can I embed the form into the index page ?
Embedding your form
In your index.html.erb, add the following line:
<%= render 'form' %>
Assuming that the form partial is stored under app/view/trader with a name _form.html.erb.
Redirect
In your traders_controller.rb, edit the create action so that the user is not redirected to what the entry they submitted. I assume that there is a line like redirect_to #trader upon a successful save on the database. Instead, use something like redirect_to root_path, or wherever you want the users redirected to.
Pop-up box
In your traders.js.coffee under app/assets/javascripts, add some codes to display alert box on a successful submission of the form. Something like:
$("#your_form").submit(function(event) {
alert("Thank you for your submission.");
});

Jquery redirect with Ajax Calls to another page Rails

I am trying to implement two pages. The first page being a selection of the items I want to show on the second page.
On my first page, I have done a selection of the items which I want to render.
On click of a button, 1. the ids of these items will be placed in an array and 2. the user will be redirected to a new page through:
window.location.replace("/schedule");
Right now, I want to achieve the following:
Do an ajax call through rails to get each of the array items. i.e. make an ajax calls to the urls of myclass/[id]. The id belonging to the items in the array.
I am not sure how I could get my array items from the current page to the next page or if there is a better way of achieving this. Any advice or suggestion will be greatly appreciated.
Add :remote => true to your form. Then, app will render your action_name.js.erb view instead of action_name.html.erb. In js file you can put code, which will repleace div without redirection, f.e.
$('#div_id').html('<%= escape_javascript render(your_partial_name) %>');
You don't need to do anything special in partial and controller action, its all the same.

Rails, link to previous page without losing content

My rails app has a basic search function that queries the database and displays a list of active records. The search results are displayed as links. When the user clicks on a link for a given search result they will be taken to a page with details of their selection and what not. I want to have a back button on this details page that will take the user back to the search results page with the search results still showing up. The way it is now the back button takes the user back to the search results page but all of the search results are gone.
You have to pass the query parameter(search text) to the details page where you have the back button.
Include the query parameter in the back button url as http://localhost:3000/search?query=foo
Capture search query information in params[:query] and take it from one page to another.
In result detail page add this:
<%= link_to 'Back', "#{:back}+#{params[:query]}", :class => 'button' %>

ActionLink back button

I have an Index method that does double duty as showing a list of posts and a queried list of posts and can also have pages so you get urls like /News/Page/1 or /News?query=test
When a user clicks through to a post at say News/Details/1 they get a simple ActionLink that takes them back to the list. BUT I want this link to take them back to the actual page they were on in terms of the paging or the query. How could I do this? I don't want to use the JavaScript history method. Here is my current ActionLink: <%=Html.ActionLink("<< Back to News List", "Index")%> and this is an example of the paging links: <%= Html.RouteLink("<< First Page", "NewsPaging", new { query = ViewData["query"], page = 0 })%>
Thanks
It would probably be easier to just use javascript to send them back to the last page in their history (without creating a link to the specific page).
history.go(-1)
I will go for a ActionLink like
<%=Html.ActionLink("<< Back to News List", "Index")%>
because user can access News/Details/1 directly and if then you have a link that uses history.go(-1) or history.back() function it will not redirect it to the Index action
Another way to do this is to create the link in the controller and assign it to a property of the model or a simple ViewBag variable (up to you). For this example, I'm just going to use ViewBag.
So in your example, going from /News/Details/1 back to /News/Page/1?some-querystring, you can do the following:
In your controller (assuming '1' is the 'id'):
ViewBag.BackButton = String.Format("/News/Page/{0}{1}", id.ToString(), Request.Url.Query);
In your view:
< Back
One draw back to this is that you must know what the previous page was/could be. In your case, you want your back button to go back to your list, so this technique should be fine.

Resources