link-to

Weird route malfunction, mix between devise and own controller

為{幸葍}努か 提交于 2019-12-24 07:58:01
问题 I've got a real weird route behavior. I spotted the line which, i think, cause the error. Here is the line (in application.html.erb) in question : <%= link_to "Official Top", :controller => "tops", :action => "show", :id => 10 %> The problem happens when i want to sign in with devise, when i go to this link : http://localhost:3000/users/sign_in using <%= link_to "sign in", new_user_session_path %> Without the line everything is fine, but when the line is present i've got this error : No route

Link_to Routing Issue With Nested Resources

旧巷老猫 提交于 2019-12-23 20:21:45
问题 I have two models Jobs and Questions. A job has many questions and questions belong to a job. I've set up the resources in the model, as well as the routes. I am having an issue trying to link_to the Show method of the questions controller on the questions#index page. My rake routes say that the path should be job_question_path with the two necessary :id's being :job_id and :id , so I tried: <td><%= link_to 'Show', job_question_path(@job, question) %></td> and got the error: No route matches

Ruby on rails link_to syntax

自古美人都是妖i 提交于 2019-12-23 07:41:02
问题 After following a tutorial Ive found. Im now redoing it again, without the scaffolding part, to learn it better. However, editing my \app\views\home\index.html.erb to contain: <h1>Rails test project</h1> <%= link_to "my blog", posts_path> I get an error: undefined local variable or method `posts_path' for #<ActionView::Base:0x4e1d954> Before I did this, I ran rake db:create , defined a migration class and ran rake db:migrate , everything without a problem. So the database should contain a

How to get link_to in Rails output an SEO friendly url?

冷暖自知 提交于 2019-12-23 02:36:35
问题 My link_to tag is: <%= link_to("My test title",{:controller=>"search", :action=>"for-sale", :id=> listing.id, :title => listing.title, :search_term => search_term}) %> and produces this ugly URL: http://mysite.com/search/for-sale/12345?title=premium+ad+%2B+photo+%5Btest%5D How can I get link_to to generate: http://mysite.com/search/for-sale/listing-title/search-term/12345 Been trying this a few different ways and cannot find much online, really appreciate any help! 回答1: Tahe a look at this

How to route from a nested resource in rails? Getting 'ActiveRecord::RecordNotFound in UsersController#show'

亡梦爱人 提交于 2019-12-23 01:21:27
问题 I have a gameplay screen, with a link to return to a players' stat page. My test user id is 0, and the mine id is 1. So the url of the gameplay screen is /users/0/mines/1 The button from gameplay back to player stats looks like this: <%= link_to "Home", user_path, id: 'link-to-hq' %> User_path seems to be correct, but when I click it, I have the error: Couldn't find User with 'id'=1 def find_user @user = User.find(params[:id]) end (This is my private find user method from my user's controller

Using link_to in a class in a Rails helper

只愿长相守 提交于 2019-12-21 09:06:35
问题 I have a rails helper using the structore below, but when I use it I get the message undefined method 'link_to' The helper is arranged as: module MyHelper class Facet def render_for_search link_to("Value", params) end end class FacetList attr_accessor :facets def initialize #Create facets end def render_for_search result = "" facets.each do |facet| result << facet.render_for_search end result end end end 回答1: This is because within the Class Facet you don't have access to the template binding

Can I make an array of links using link_to in Rails?

六月ゝ 毕业季﹏ 提交于 2019-12-21 07:29:40
问题 I have a list of values in url/title pairs that I'd like to display. (More specifically, each object has its own list of links, some with 0, some with 1, some with more.) I would like them to appear in a list that is comma-separated. So I wrote this in my .erb file: <%= links.map{|wl| link_to wl.title, wl.url}.join(', ') %> Somewhat to my surprise, this displayed a comma-separated list of the HTML code for the links I wanted to create; that is, it was taking all the angle brackets and

Button_to in email not posting

孤街浪徒 提交于 2019-12-21 05:52:04
问题 SEE UPDATE for evolution of this question On my website, each user has a dashboard where s/he can click a link to either ACCEPT or DECLINE an request. Depending on what is clicked, the Request record is then PATCHed with the relevant status. To make it easier for users, I'm trying to embed this dashboard in an email to them so that they never have to go to the website directly; think of an email that looks like this: Hi there, You have the following requests, click ACCEPT/DECLINE next to the

Button_to in email not posting

泪湿孤枕 提交于 2019-12-21 05:51:16
问题 SEE UPDATE for evolution of this question On my website, each user has a dashboard where s/he can click a link to either ACCEPT or DECLINE an request. Depending on what is clicked, the Request record is then PATCHed with the relevant status. To make it easier for users, I'm trying to embed this dashboard in an email to them so that they never have to go to the website directly; think of an email that looks like this: Hi there, You have the following requests, click ACCEPT/DECLINE next to the

ruby on rails link_to delete method not working

一曲冷凌霜 提交于 2019-12-21 04:24:06
问题 I am trying to delete a post using the code below: <%= link_to 'Destroy', post, :method => :delete, :onclick => "return confirm('Are you sure you want to delete this post?')" %> which does not work... it simply redirects me back to the post (posts/:id} however, if i use the following code it works <%= button_to 'Destroy', post, method: :delete, :onclick => "return confirm('Are you sure you want to delete this post?')" %> is it possible to make link_to behave as button_to in this case? EDIT: