Rails - link_to a specific item#show - ruby-on-rails

Using the Rails model and controller, I have created a few items. Each item has a year (2011, 2012, 2013, 2014, 2015). I can access the items#show by using a vanity URL that I defined: example.com/items/2015-item. This works for any year and item.
In the top navigation bar, I have a button that when clicked, I want it to link directly to the 2015-item page. The current link is:
link_to ('items/2015-item')
This works when I click it from the home page, but if I am already on the 2015-item page, I get the link: example.com/items/items/2015-item. Obviously it is tacking on the extra items directory, but I haven't been able to figure out a way to define the item_path in routes.rb.
Any suggestions would be appreciated!

Try using this instead
link_to('/items/2015-item')

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 to redirect back to Listing page?

I've got some pages going on. Each page shows Listings of items that users wish to sell, along with their prices and descriptions. At the bottom of the page is a link for creating a new listing.
What I want to do is have the back button return the user to the page they created he listing on -- NOT the index of all listings.
I can't just change the back button to
link_to 'Back', pages_universityofconnecticut_path
because it will link to the University of Connecticut even when used on Harvard's page. I hope that makes sense. How do I go about doing this?
I have used this line in my view to display only the listings where the school matches the page.
here's the solution of your problem, an excellent way by ryan
http://railscasts.com/episodes/131-going-back

Making A Back Link Going To Same Page Left(Ruby On Rails)

I'm using Kaminari pagination on a site, and when the user leaves the page and clicks the back link it goes back to the first page.
What I want is for the back link to go to the same page left. I know I should use a session variable for this, but I'm pretty new to Ruby On Rails so I'm not 100% positive on the syntax here.
Would love some help.
<%= link_to_function "Back", "history.go(-1);return true;" %>
I should add that it's a good practice to code links to pages as <a> tags rather than creating a form in your HTML for that purpose.
If you need to style the link to look like a button, do that in the CSS.

RoR & ACTS_AS_Tree & display show page from database vs. display content

All,
Working on a RoR app for work. Finally got acts as tree working with a database connection (railscast.com episode 162). Trying to shift from displaying content in the database to redirecting to the contents of the page.content database entry -- any ideas? I've tried simply replacing the display action with redirect_to, no dice. Googling all over the place - out of time - help..
My flow is as follows:
pages.rb: acts_as_tree command
application.html.erb: menu display for root entries
pages/show.html.erb:
- displays submenu, no problem
- display breadcrumbs, no problem
- display page name, no problem (envision removing this once redirect works)
- display contents of page.content:
<%= simple_format #page.content %>
no problem
Problem is I want to redirect to the contents of #page.content and not display it. Or I can shift to a different controller action, but the idea is that I need to be able to use the navigation menu to move around to different pages (that alrady exist) vs just showing the content. Ideas?
Thanks,
Adam

Orbeon: creating my own delete button

2/28: Seems the Go uri is only if you create your own persisten layer. I'm going to try and use a link on my form to do this. If I can figure out how to find the form_id of the current form.
Original Question:
I'm trying to restrict who can delete a form instance. It seems if people can get to the form-runner summary page, they can click the delete button and delete a form (even if they are not allowed to do any "/orbeon/fr/hr/expense-report/edit/*" options.
Anyone found a way around this issue. I wonder if we could use the GO button on the form /edit/ view to build our own delete feature.
If I look at the page source from the hr/expense-report/edit/f36b446c3ddbf7c63ec033d5c6fa7ce4 view, that the from does have the details to the actual form instance.
Example:
form id="xforms-form" class="xforms-form xforms-initially-hidden xforms-layout-nospan" action="/orbeon/fr/Test/Hidden_Search/edit/f36b446c3ddbf7c63ec033d5c6fa7ce4"
I wonder if that information could be passed to the "GO" button, if I have that on my page?
Right now, if users can access the Form Runner summary page, they can also access the "delete" button. Showing the "delete" button on the summary page for some users but not others, requires a change to Form Runner, which shouldn't very complicated.
For instance, if you only want the "delete" button to be shown for users with the role can-delete, on this xforms:bind of fr/summary/view.xhtml add the attribute:
relevant="xxforms:is-user-in-role('can-delete')"

Resources