html - Rails redirects back again to the same page after submitting form -


[updated question, please see latter half]

i'm bulding simple web application has simple sign-up/login form. system want have is

  • you put name , keyword in form.(at /save_user.html)
  • press "confirm" link
  • check if username used or not. true -> update, false -> register
  • redirect /goodbye.html (controller)

now testing new username/keyword set every time. problem is, final output /save_update , , ends error says no parameters givin. (of course no parameters givin)

i's there can this? thankyou!

controller

# # register user # def save_user   point_id = session[:point_id]   @point = point.find(point_id) end  def save_update   username = params[:user][:name]   keyword = params[:user][:key]   point_id = session[:point_id]   #   # if username exists, match password.   # if not, create new.   #   user = user.find_by_username(username)   if user     if user.keyword == digest::sha1.hexdigest(user.salt + keyword)       # user exists!       render text: 'matched!'     else       # keyword wrong       render text:"keyword wrong.."     end   else     # save new user!     user = user.create(salt:securerandom.hex(4))     user.update(         username:username,         keyword:digest::sha1.hexdigest(user.salt + keyword)     )     point = point.find(point_id)     point.update(:user_id => user.id)      return redirect_to action: :goodbye   end end  def goodbye   # goodbye.html.erb exists   point_id = session[:point_id]   point = point.find(point_id)   @username = user.find(point.user_id).username end 

view (save_user.html.erb)

<%= form_tag({action: :save_update}, {name: :user_info, method: :post}) -%>     <p>username(英数字):       <%= text_field_tag("user[name]", "", options:{ id:'user_name' }) %></p>     <p>keyword(英数字)  :       <%= text_field_tag("user[key]", "", options:{ id:'user_key' }) %></p>     <br>     <!-- see diagnose2_helper.rb! ↓ -->     <%= submit_link_tag(name = "confirm", form_id = "user_info", action="save_update") %> <% end %> 

helper

def submit_link_tag(name = "submit", form_id, action)#, options = {})   content_tag( :a, name, { "href" => "./#{action}", "onclick" => "document.#{form_id}.submit();"}) end 


i realized 2 problems code, though changed it, didn't solve it.

  1. in save_user.html.erb, had form_tag({action: :save_update} ..., , submit_link_tag same action in it. calling save_upate action twice.

  2. even when deleted {action: :save_update}, i've got same error, time seems because submit_link doesn't send hash.

i re-think code scratch now, if has ideas issue, thanks, it'll helpful.

try this

redirect_to action: :goodbye 

not

return redirect_to action: :goodbye 

hope work you.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -