My application should behave like this:
- My application manages (among others) a resource called "Dicts", i.e.
there is a dicts_controller, and my routes.rb contains a "resources
:dicts".
- I have a home page (starting page), which will eventually contain some
user authentification (not implemente yet), and then allow the user to
manage the Dicts objects. I have a home_controller and my routes.rb
contains
match '/login', to: 'home#login', via: 'get'
root 'home#init'
and init.html.erb contains the login form.
So far it's quite conventional. Now to the perhaps unusual part:
- For convenience to the user, the login form contains not only fields
for entering the user data (userid, password), but also an entry field
for a Dicts object, and *two* submit buttons, one with the meaning of
"login and create a new dictionary", and the other one with the meaning
"login and open a existing dictionary":
<%= form_tag("/login",method:"get", enforce_utf8:true) do %>
....
<%= submit_tag(value="Create New Dictionary", class:
'kanren_button', name: 'create') %>
<%= submit_tag(value="Open/Pick Existing Dictionary", class:
'kanren_button', name: 'open') %>
<% end %>
Now the problem:
My HomeController.login method checks, whether the user is authorized,
and if he is, needs to go to the Dict controller and either :create a
new Dict object or :show an existing one.
My problem is that to :create a Dict, would require a POST action (if I
want to stick with the REST model), but a
redirect_to url_for(:controller => dicts,...)
will always create a GET request.
I was thinking of the workaround to use
redirect_to url_for(:controller => :dicts, :action => :new)
and inside Dicts#new use the parameters passed, to create a new Dicts
object, and (if successful) redirect to Dicts#show or whatever, but this
doesn't seem to be an elegant solution.
Another possibility is to invoke Dicts.create from my Home.login method,
but this doesn't seem to be good style either.
Any suggestions on how to proceed?
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3a716898bf5663774754e11db41c90b6%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment