I am not a huge fan of an approach that would need to redirect in this way.
Instead, why not create a new class called login or something like that.
To see a possible usage checkout the following article
http://matthewrobertson.org/blog/2012/09/20/decoupling-rails-forms-from-the-database/
You will need to adapt a bit to your needs, but the basics are sound and
should apply nicely.
On 6/4/14, 9:22 AM, Ronald Fischer wrote:
> 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?
>
--
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/538F207D.7020408%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment