routes

Passing id through an link href in Laravel

前提是你 提交于 2019-12-10 13:34:26
问题 is it possible to pass id through an link href in Laravel and display that page like /projects/display/2. I have this link: <td><a href="{{ url('projects/display', $projects->id) }}" class="btn btn-info">View</a></td> It displays the id when hovering over the link as /projects/display/2. But whenever i click on the link i get an error message of: Sorry, the page you are looking for could not be found. I have a view setup called projects/display, plus routes and controller. routes: <?php Route

How do I define a catch-all route for an ASP.NET MVC site?

巧了我就是萌 提交于 2019-12-10 12:50:00
问题 I have a news site with articles tagged in categories. My Controller is called "Category" and this URL: http://mysite.com/Category/Sport passes Sport to action Index in controller Category . I want to allow the following URLs: http://mysite.com/Sport/Hockey http://mysite.com/Sport/Football http://mysite.com/Science/Evolution Which passes all category information to action Index in controller Category . How do I create a catch-all route that handles all these and shuttles them to category? 回答1

Routing error in activerecord reputation gem in rails 4

眉间皱痕 提交于 2019-12-10 11:48:33
问题 Hello I'm new to rails 4 I am working on project where we can post and rate it. I have used activerecord reputation gem. I have been following the http://railscasts.com/episodes/364-active-record-reputation-system video. I am stuck at the routing point. When I click on upvote or downvote it shows me error. my routes.rb file has resources :posts do resources :comments, :only => [:create] member { post :vote } end get "posts/create" get "posts/destroy" get "posts/new" get "posts/index" get

Ruby Sinatra - Protecting routes with authentication

和自甴很熟 提交于 2019-12-10 11:45:33
问题 I have a Ruby class that basically authenticates a user to an LDAP directory as follows. The DirectoryUser class is using the net/ldap gem to do this. When called the class returns either a 'true' if the user is authenticated or 'false' if not. >>DirectoryUser.authenticate('user', 'password') #True I want to use this mechanism to protect my routes in a basic Sinatra application for multiple users. Is there a recommended way to do this that follows best practise? Could somebody show how this

Is it possible to pass object as route value in mvc 3?

僤鯓⒐⒋嵵緔 提交于 2019-12-10 11:27:46
问题 I'm trying to refactor some of my code and i'm wondering if it is possible something like this: This is part of my cshtml: <a href="@Url.Action("Vote", "Ideas", new { id = item.Idea.Id, pageMetadata = Model.PageMetadata, numberOfVotes = 2 })"> This is invoking action: public ActionResult Vote(string id,PageMetadata pageMetadata, int numberOfVotes = 1) And PageMetadata is my class. When im debbuging in cshtml site pageMetadata is correct,but when action is invoking pageMetadata it's becoming

Bind /action/1,2,3 to List<int>

半腔热情 提交于 2019-12-10 11:09:18
问题 In my API, I'd like to have routes like GET /api/v1/widgets/1,2,3 and GET /api/v1/widgets/best-widget,major-widget,bob-the-widget public class WidgetsController : MyApiController { public ActionResult Show(IEnumerable<int> ids) { } public ActionResult Show(IEnumerable<string> names) { } } I've got routes set up to get me to the action, but I can't figure out how to turn 1,2,3 into new List<int>(){1, 2, 3} and so on. Of course, I could just take a string and parse it in my action, but I'd like

Route patterns vs individual routes

[亡魂溺海] 提交于 2019-12-10 11:05:48
问题 Currently I have a controller which looks something like this: public class MyController : Controller { public ActionResult Action1 (int id1, int id2) { } public ActionResult Action2 (int id3, int id4) { } } As you can see both my controllers have the same parameter "pattern", two non-nullable signed integers. My route config looks like this: routes.MapRoute( name: "Action2", url: "My/Action2/{id3}-{id4}", defaults: new { controller = "My", action = "Action2", id3 = 0, id4 = 0 } ); routes

Dynamically construct RESTful route using Rails

試著忘記壹切 提交于 2019-12-10 10:55:35
问题 I'm trying to write a helper method that accepts the name of a plural resource and returns a corresponding link. The essence of the method is: def get_link(resource) link_to "#{resource.capitalize}", resource_path end —Clearly the resource_path part above doesn't work. What I'd like is to be able to pass foos to get foos_path and bars to get bars_path etc. How can I do that? I can't quite work out the syntax. 回答1: def get_link(resource) link_to "#{resource.capitalize}", send("#{resource}_path

How to get optional language parameter from URL in Express routes?

旧街凉风 提交于 2019-12-10 10:33:24
问题 I'm stuck with a stupid problem: How to work with optional locale parameter? That's what I mean: For example, I have frontpage and contacts , here is routes: app.get('/', frontpage.get); app.get('/contacts', contacts.get); Now I'm trying to add localization to my site app.all('/:lang?*', language.all); -> detect and set locale app.get('/:lang?', frontpage.get); app.get('/:lang?/contacts', contacts.get); The only problem is when I don't use lang-parameter in URL: mysite.com/contacts because

Only allow URL's specified in routes to be seen in Codeigniter

自古美人都是妖i 提交于 2019-12-10 10:27:20
问题 If I have a controller called articles, which has a method called view_articles, a user can type in http://example.com/articles/view_articles/some-post and have it return a page. I have specified a route to be http://example.com/article/post-name. How can I make it so that only the URL specified in the route is visible? Is there a way for articles/view_articles/some-post to show a 404 instead of showing the same page as the route URL? I am trying to prevent duplication for SEO purposes. 回答1: