On Sep 9, 10:54 am, Misha Ognev <li...@ruby-forum.com> wrote: > Hi guys, the next problem: > > I create a controller, (/controllers/rmagick_controller.rb), which have > aim to test an captcha > > Actions: > def download # creates an captcha image > def show # show the page where image took place > def check # must check right captcha or wrong > > views/rmagick/show.html.erb: > > > <div id="captcha"> > > <p><%= image_tag download_rmagick_path %></p> > > > <p><% form_tag check_rmagick_path do %> > > <p><%= text_field_tag :captcha %></p> > > <p><%= submit_tag "Submit" %></p> > > <% end %> > > </p> > > </div> > > config/routes.rb: > > > resources :rmagick do > > get "download", :on => :member > > get "check", :on => :member > > end
Rails understand this as creating urls like rmagick/123/download, i.e. it things there are actual rmagick entities which supports a download action This means that when you call download_rmagick_path rails is expecting you to supply it with the id of the rmagick entity. If you don't rails won't be able to generate a url. You'd probably need to either switch to a singleton resource, make those actions collection actions, use match rather than creating a resource. The rails routing guide should explain the difference between these actions > > So, there are 2 problems: > > 1) Routes problem. If I'm write in config/routes.rb something like this: > > > get "rmagick/show" > > get "rmagick/download" > > get "rmagick/check" > > I catch this output:> No route matches {:action=>"download", > :controller=>"rmagick"} > > But I'm place get "rmagick/download" in routes.rb. Why it doesn't work? > (it can't find download_rmagick_path) > > So, if I use resources :rmagick do ... I see an show.html.erb when i > write something other than "show" text, ie in this link > 127.0.0.1:3000/rmagick/jjvniuv I also will see show action.why? How I > can change this? Where is the problem? That's what it's supposed to do - given the routes you've defined, / rmagick/jjvniuv is the path for the rmagick entity with the id jjvniuv > > 2) Problem with form_tag. So, you see the code above. When I put captcha > value and press "submit" button, I don't go to rmagick/check, I go to > rmagick/show/check. Why? > I'm surprised it does anything at all. You've got the same problem as earlier - a route that is expecting an id, but you're not giving it an id. You might also want to look at the recaptcha captcha - it's very easy to integrate Fred > 3) When I'll create all of this, how I can do interaction between other > pages and captcha? > > -- > Posted viahttp://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.