link-to

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

白昼怎懂夜的黑 提交于 2019-12-07 15:13:28
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.) For some reason, it's grabbing the MINES id (of 1), not the user id (of 0)!!! The route im using is

How do you pass multiple arguments to nested route paths in Rails?

淺唱寂寞╮ 提交于 2019-12-07 06:09:19
问题 I am new to Rails and normally set up a link_to helper for a normal unnested route like so: link_to "Delete", article_path(article.id), method: :delete, data: {confirm: "Are you sure?"} However I am learning about nested routes and it seems I need to provide the path with two arguments for example: link_to "(Delete)", article_comments_path(comment.article_id, comment.id), method: :delete, data:{comfirm: 'Are you sure?'} However this does not seem to work. I have seen that you can format the

Ruby on Rails link_to internal id

邮差的信 提交于 2019-12-07 03:27:08
问题 How do i use a link_to inorder to go to a specific (html) ID on a page normally if i wanted to go to the "whatever_id" on a page i could use <a href="http://www.example.com/index/mypage#whatever_id>Click Here</a> but i would like to use my link_to <%= link_to "click here" , {:action => "mypage", :controller => "index" }, :id => "#whatever_id"%> helper methods. Does anyone know how to do this? Is it possible? Rails 2.3.4 回答1: link_to can add anchors to a URL. From the documentation, link_to

Rails 3 - How do you create a new record from link_to

岁酱吖の 提交于 2019-12-06 23:49:33
问题 I'm trying to create a 'tag' functionality which allows a user to "tag" items in which they are interested. Here is my model class tag belongs_to :user belongs_to :item end The corresponding DB table has the necessary :user_id and :item_id fields. In the list of :items I want a link next to each :item that allows the user to tag the :item . Since I know the :user_id and the :item_id , I want to create a new :tag record, set the id fields, and save the record - all with no user intervention. I

rails 3 render partial with params

风流意气都作罢 提交于 2019-12-06 18:49:51
问题 I'm having a problem passing some parameters to a partial. No matter what I've tried the params don't pass when the partial is rendered. I am using a jquery tabbed layout, and each tab displays work orders in a particular status and also based on a range of dates. I am using the params :sort_filter and :status_filter to accomplish this. My original code is here, but I want to change this to render partials in the link_to's instead of the way it's listed here: <ul> <li><%= link_to "Active",

Ruby on Rails: link-to using post method but parameters are in the URL

别等时光非礼了梦想. 提交于 2019-12-06 18:46:37
问题 I'm using link_to 'My link', path(:arg1 => session[:arg1], :arg2 => session[:arg2],:arg3 => anyobject.id), :method => :post but the HTML link being generated includes (arg1,arg2,arg3) as URL query parameters. How can remove them? Did I miss something in the documentation? 回答1: A link_to will always put the arguments into the query string as it is creating a get-style HTML link - even if you put :method => :post that just appends an extra ("special") argument _method . What I think you really

Ruby on Rails link_to With put Method

久未见 提交于 2019-12-06 18:23:17
问题 I'm new to Rails, and I'm trying to use the link_to helper to create a link that issues a PUT request instead of a GET request. Specifically, I'm trying to create a link that activates a user's account in my app from the admin's panel. I'm using Rails 3.0.5. My routes.rb file has: match '/admin/users/:id/activate' => 'admin#activate_user', :action => :activate_user, :via => :put My view has: link_to 'Activate', :action => :activate_user, :id => user.id, :method => :put However this generates

rails - how to change database values with a link

依然范特西╮ 提交于 2019-12-06 17:30:29
I am making a website using rails and I am in desperate need of help of how do I create a link that when clicked on it will update an attribute in the database but only when clicked on.I have this code: <%= link_to (myproperty_path) do %> <% @player.update_attribute("energy", @player.energy + 2) %><span>Take a Nap</span> <%end%> but the problem with this is that whenever I refresh the page it updates the attribute and when I go to another page on the website it updates the attribute again. It works when I click on it but I want it to work only when clicked on and that's it. Also, if I have two

How to fix broken devise routing under journey 1.0.4

Deadly 提交于 2019-12-06 16:22:21
I began troubleshooting my "sudden" broken routes problem in this SO question: Devise /users/sign_in redirecting to wrong controller and with help I was able to isolate the issue to the upgrade from journey 1.0.3 to 1.0.4 that occurred when I updated to rails 3.2.7. As you know, we need to be at rails 3.2.8, to apply important security fixes, but this means I must use journey 1.0.4, which breaks my devise routes. For instance, my custom new_user_session route is welcome#welcome, but it is being decoded to devise/welcome#welcome which does not exist. Has anybody else run into this love triangle

Rails: method for 'standardizing' url input from users?

拜拜、爱过 提交于 2019-12-06 05:54:14
问题 I'd like Users in my Rails app to be able to share a link to their personal website in their profile. Simple enough, I have a column called website and a text field they can fill in to make it work. However, when I display this in a view there's a problem. If I use the link_to helper then whether or not the person included the http:// determines whether or not the url will work. But, if I automatically prepend http:// then I get it twice for users who DID put it in their url. I'm sure this is