Is there something wrong with my link_to?

<%= link_to 'show', :controller=>:users, :action=>:show, :id=>u.id, :confirm=>'are you sure?' %> <%= link_to 'reset pass.', :controller=>:users, :action=>:reset_password, :id=>u.id, :confirm=>'RESET PASSWORD, are you sure?' %>

The first link works fine, but the second is really strange... sometimes it works, and sometimes is doesn't and causes such an error:

LoadError in UsersController#index

Expected /home/anonym/Documents/RubyOnRails/authorisation/loginout/app/controllers/users_controller.rb to define UsersController

Moreover it doesn't show confirmation box. Anyway if I remove :confirm option the first error occurs anyway from time to time.

Controller:

#users_controller.rb class UsersController < ApplicationController ... def reset_password @user=User.find_by_id(params[:id]) ...

Routes:

#routes.rb match 'users/:id/reset_password', :to=>"users#reset_password"

It could be understandable to me if it failed everytime but is it's kind of random.

Any ideas why?

UPDATE

This little modification in controller seemed to fix the problem.

#Thread.new{UserMailer.reset_password(@user, passwd).deliver} UserMailer.reset_password(@user, passwd).deliver

This also caused my sqlite database to collapse (if I clicked the link very fast a few times).

Do you know why this thread might have been such a killer?

And there still is the question why there is no confirmation box?

UPDATE

Started GET "/users/2/reset_password?confirm=RESET+PASSWORD%2C+are+you+sure%3F" for 127.0.0.1 at 2012-02-06 15:03:57 +0100 Processing by UsersController#reset_password as HTML Parameters: {"confirm"=>"RESET PASSWORD, are you sure?", "id"=>"2"} [1m[36mUser Load (0.2ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1[0m [1m[35mUser Load (0.4ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1 [1m[36m (0.5ms)[0m [1mSELECT 1 FROM "users" WHERE ("users"."email" = '[email protected]' AND "users"."id" != 2) LIMIT 1[0m [1m[35m (0.3ms)[0m UPDATE "users" SET "last_support_email_sent_time" = '2012-02-06 14:03:58.182567', "encrypted_password" = '5380187f533d14e2867667f8c2c9dc6671b1d930ff892a8cb4da7cdda99d01c8', "updated_at" = '2012-02-06 14:03:58.186194' WHERE "users"."id" = 2 Rendered /home/anonym/Documents/RubyOnRails/authorisation/loginout/app/views/user_mailer/reset_password.html.erb (0.2ms) Sent mail to [email protected] (1270ms) Date: Mon, 06 Feb 2012 15:03:58 +0100 from: User service To: [email protected] Message-ID: <[email protected]> Subject: Your new password Mime-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Hello ,</br> Your new password is: 469ff56728 Redirected to http://localhost:3000/users Completed 302 Found in 1407ms Started GET "/users" for 127.0.0.1 at 2012-02-06 15:03:59 +0100 Processing by UsersController#index as HTML [1m[36mUser Load (0.3ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1[0m [1m[35mUser Load (1.1ms)[0m SELECT "users".* FROM "users" ORDER BY email Rendered shared/_add_to_user_index_row.html.erb (0.1ms) Rendered shared/_add_to_user_index_row.html.erb (0.1ms) Rendered shared/_add_to_user_index_row.html.erb (0.1ms) Rendered shared/_add_to_user_index_row.html.erb (0.1ms) Rendered shared/_add_to_user_index_row.html.erb (0.1ms) Rendered shared/_add_to_user_index_row.html.erb (0.2ms) Rendered /home/anonym/Documents/RubyOnRails/authorisation/loginout/app/views/users/index.html.erb within layouts/application (75.8ms) Completed 200 OK in 197ms (Views: 132.5ms | ActiveRecord: 2.6ms) Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100 Served asset /jquery_ujs.js - 304 Not Modified (0ms) Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100 Served asset /application.css - 304 Not Modified (0ms) Started GET "/assets/loginout.css" for 127.0.0.1 at 2012-02-06 15:04:00 +0100 Served asset /loginout.css - 404 Not Found (39ms) ActionController::RoutingError (No route matches [GET] "/assets/loginout.css"): Rendered /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (2.1ms) Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100 Served asset /jquery.js - 304 Not Modified (1ms) Started GET "/assets/messages.js?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100 Served asset /messages.js - 304 Not Modified (1ms) Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100 Served asset /application.js - 304 Not Modified (2ms) Started GET "/assets/auth_engine.css?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100 Served asset /auth_engine.css - 304 Not Modified (2ms) Started GET "/assets/sessions.css?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100 Served asset /sessions.css - 304 Not Modified (0ms) Started GET "/assets/users.css?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100 Served asset /users.css - 304 Not Modified (0ms) Started GET "/users" for 127.0.0.1 at 2012-02-06 15:04:35 +0100 SQLite3::SQLException: unsupported file format: SELECT name FROM sqlite_master WHERE type = 'table' AND NOT name = 'sqlite_sequence' ActiveRecord::StatementInvalid (SQLite3::SQLException: unsupported file format: SELECT name FROM sqlite_master WHERE type = 'table' AND NOT name = 'sqlite_sequence' ):

After that database is broken - server restart doesn't help. This occures from time to time eventhough I no longer use Threads.

-------------Problems Reply------------

Rails is not thread-safe. If you need to perform background operations, use something like Spawn or DelayedJob

As for the confirmation, do you have an application.js in your app/assets/javascript folder, and do you have <%= javascript_include_tag "application" %> in the <head> of your layout?

If the application.js file isn't being loaded, none of the Rails JS will run, which includes confirmations.

Update: I see the problem now. The link_to method takes two types of options, first the options for routing, then the options for the HTML. :confirm is one of the HTML options.

If you're going to pass routing and HTML options, you need to separate the routing options into their own hash first, like so:

<%= link_to 'show', { :controller=>:users, :action=>:show, :id=>u.id }, :confirm=>'are you sure?' %>

<%= link_to 'reset pass.', { :controller=>:users, :action=>:reset_password, :id=>u.id }, :confirm=>'RESET PASSWORD, are you sure?' %>

As the log demonstrates, your confirm is being passed as part of the path generated by the link_to, rather than being included in the HTML of the generated a element.

Category:ruby on rails Views:0 Time:2012-02-04

Related post

  • How do I use the Rails helper link_to RESTfully in this situation? 2008-10-08

    I basically want to use link_to to link to the index method of a controller. I tried: <%= link_to 'Recipes', Recipe %> but that outputs: <a href="/recipes/Recipe">Recipes</a> Which is clearly not right, if it left off that last bit

  • How to test with RSpec a Rails plugin using "link_to" and "current_page?" 2008-10-12

    I'm writing a Rails plugin that builds up a menu in a view. I'm using link_to to build the link and current_page? to set class="active" on the current page. I've included ActionView::Helpers::UrlHelper so I can use link_to. To get current_page? worki

  • Rails active_resource require JS to do delete by link_to? 2008-12-19

    When I use link_to :method=>:delete, what rails has generated is a javascript click, which is not nice if you do come across situation your client just have javascript disabled. That seems a bad idea to me. Any chance to get around this? ---------

  • Modifying the behavior of link_to in a Redmine installation (ruby on rails) 2009-02-04

    I'm trying to modify the UI of a Redmine installation (Redmine 0.7.3.devel.2093 (MySQL)). When you view a project in Redmine, it generates a list of all the subprojects for the project. For example, app/views/projects/index.rhtml calls the link_to fu

  • Ruby on rails link_to syntax 2009-02-13

    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_pa

  • Link_to method and onClick event in Rails 2009-03-30

    How do I create a link of this type... <a href="#" onClick="document.getElementById('search').value=this.value"> ...using method link_to in Rails? I couldn't figure it out from http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.htm

  • how do I use link_to link to different controller and model? 2009-04-21

    I currently have the following for-loop. This is in the 'view/vendor/show.html'. I set up a 'vendor :has_many :reviews' and this is the for-loop: <% for review in @vendor.reviews %> <%= review.user_id %> <%= review.summary %><br

  • Does link_to have :before and/or :after like link_to_remote 2009-06-08

    I am converting some of my link_to_remote generators with link_to as the AJAX calls were creating issues with my browser back button. (Silly noob mistakes!) My application has many pages that have a long wait cycle (for various reasons out of my cont

  • How do I wrap link_to around some html ruby code? 2009-07-06

    How do I wrap a link around view code? I can't figure out how to pass multiple lines with ruby code to a single link_to method. The result I am looking for is that you click the column and get the show page: <div class="subcolumns"> <div cla

  • Rails Polymorphic relationship and link_to 2009-08-16

    Here's my Schema class Menu < ActiveRecord::Base belongs_to :menuable, :polymorphic => true end class Page < ActiveRecord::Base has_one :menu, :as => :menuable end class Links < ActiveRecord::Base has_one :menu, :as => :menuable end

  • Add events to anchors when using link_to and :method => :post instead of inline javascript? 2009-08-17

    So I'm jumping into Ruby on Rails with Agile Web Development with Rails. I got to the part where you use: <%= link_to (image_tag(product.image_url), {:action => :add_to_cart, :id => product}, :method => :post) %> In an attempt to be RE

  • Rails `link_to` method posting multiple times 2009-08-25

    [see later answer for more] I think this is just a simple rails question, and mostly on how i've named my models and reference them in my view. So a little background, I'm using the vote_fu plugin, which I think is great, however I'm having a hard ti

  • Link_to action in nested controller? 2009-08-25

    So I've created an action, lets call it 'raise' in the controller 'elevator'. 'elevator' is nested in 'building'. What routes should I create, or what link_to url can I make so /buldings/2/elevators/4/raise will work? Thanks, Elliot --------------Sol

  • link_to action is create or index, depending on where the code is 2009-09-15

    I want to cycle through each page of a paginated model's index. I'm using jquery to cycle through the pages. I find the link_to expression is calling the create action when called by jquery. The link_to expressions calls the index action under any ot

  • Ruby On Rails: using arrays with link_to 2009-09-21

    I was curious on how to use arrays in the link_to method in ruby on rails for example: Controller: def index @test = [1,2,3] end View: <%= link_to "test", {:action => 'index'}, :test => @test %> When looking at the source then, I end up w

  • link_to create and destroy a resource from a different resource 2009-09-30

    The code below is working but I want to know if there is a better way to do it. Is this the correct RESTful way to do this? Any suggestions would be helpful. The basic requirement is that I need a way to create and destroy a membership from places/sh

  • Why is link_to adding an id to its output when I don't pass a model id? 2009-10-09

    I'm using Rails 2.2.2 with the old school routes (i.e. I'm not being RESTful) and I'm noticing strange behavior coming from the Rails link_to method. Here is my call: link_to("my description", { :controller => controller, :action => action }, :

  • Rails - link_to, routes and nested resources 2009-10-10

    As my understanding on nested resources, on edge Rails, should not link_to 'User posts', @user.posts point to /users/:id/posts ? The routes.rb file contains map.resources :users, :has_many => :posts If this is not the default behavior, can it be a

  • Why does this not work: link_to(current_user) do 2009-10-14

    <%= link_to(current_user) do %> #show other stuff between anchors like this: #<a href="/user/bob">show other stuff between anchors</a> <% end %> The error I get is: compile error syntax error, unexpected ')' ...t(( link_to(cur

  • can link_to lead to rendering sth? 2009-11-10

    i want to render a partial within a view. so that when button MORE is clicked everything stays the same just additional characters are shown. in my case the whole article. <%= @article1.content[0..300] + "..." %> <%= link_to "more", .......

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.175 (s). 11 q(s)