Ruby on Rails. Devise. Registration form in yield - ruby-on-rails-3

I application.html.erb I add <%= yield %>. I want to show registration page (/users/sign_up) with header and footer in application.html.erb. As I understand contant from /device/registration/new.html.erb must contain in yield, but I get registration page withot templates(header and footer).
How I could show registration form in yiled?
I use RoR 3.2.12. Sorry for my English. Thanks.

If you get the registration page without the layout, then chances are you have a :layout => false triggered somewhere upstream.

Related

how to post :create from the default update url, rails 3

I'm sure this is pretty basic, but I'm somewhat new to rails and struggling to find a solution via search.
I'm implementing a message model to enable private messaging on a forum. I have the models resource nested within a users resource.
Currently the model works, but I want to enable a user to reply to a private message directly on the message show page. I.e users/1/messages/16 instead of users/1/messages/new. Currently this is the default route for 'update' within the MessagesController. Is there anyway to make the form on this page hit the 'create' action within the controller, instead of the 'update'?
Thanks.
Sure, I would try something like this:
On your show page just add a new form.
<%= form_for :message, :url => new_user_message_path do |f| %>
...
<% end %>
You can check the routes of your application using this command:
bundle exec rake routes
I suggest you to read the rails guide: http://guides.rubyonrails.org/

Rails authenticate_customer before_filter Jquerymobile "error loading page"

I'm using Rails3 and jquerymobile. When I click a link like /edit_profile, for annonymous users should redirect to login page. Jquery mobile shows a popup with the message "error loading page".
Thanks
The problem is that jquery mobile uses AJAX calls for the link_to methods, and rails doesn't support that.
In my case, I made it a regular link_to (non-AJAX based) by adding the following to my link
data-ajax="false"
In the link_to options, i.e:
link_to 'Model', {:controller => "models", :action => "any_action"}, "data-ajax" => "false"
I hope that helps someone someday.
Cheers!
Yohann.

Changing HTTP method to POST with link_to

I'm using Rails 3.1 here, and I've got the following code in my view:
<%= link_to "again!", main_pick_path,{:method => :post, :var => #var} %>
The idea is to create a link (not a button) which, when clicked, calls the pick action of the main controller, passing the value of #var in params via a POST request.
This code generates the following HTML in my browser:
a href="/main/pick" data-method="post" rel="nofollow" var="foo">again!</a>
However when I click the link I am still sending a GET request. Is this a limitation of my browser, Chrome? From a design standpoint, should I be using a GET request instead and putting the variable into the URL? Are hyperlinks simply incapable of using the POST method? Is there life after death?
Thanks in advance
You can only do this with AJAX or firing a FORM. The tag A cant do a POST "alone".

Rails 3 render layout except for root_url

I want to have a different layout for the home page (root_url) than the other pages in my web app. I would like to be able to use <%= render 'layouts/pages' %> for pages that are not the home page. How do I go about doing this?
Majority
The best way to do this is to name the layout for the majority of your app layouts/application - this way, Rails will automatically assume this layout for that majority without you needing to do anything else.
Home
For your home page, you can add this line to the bottom of your controller action:
render :layout => "home"
This will tell Rails not to use application, but instead to point to your home/root page's layout, which in this case would be located at layouts/home.

Rails login partial in different controller

Hey,
I'm pretty new to rails and for learning effect, I try to implement my own authorization system.
Right now I'm having a Page Controller to control some static pages and nothing more, and a Session Controller where I plan to implement most of the authorization process.
My problem is, I have no clue how to get my partial to use the sessions-controller, when I add it to one of the static pages controlled by the pages controller.
It stated out with this http://ruby.railstutorial.org/chapters/sign-in-sign-out#top but i don't want it on an extra page.
so I tried setting the routes and I got an exception "no path found for '/'" as soon as I deleted "resources :sessions" it worked fine again.
my partial looks like this:
<%= form_for(User.new) do |f| %>
<%= f.submit "Login" %>
<% end %>
there's also a div class="action" block around the submit but can't find out how to escape it
this is included into my home via
<%= render 'sessions/new' %>
Thanks for your help
edit my solution:
I added to routes.rb:
resources :sessions
Furthermore I changed form_for(#user) to
<%= form_for(:session, url => sessions_path)
so this works.
I Highly recommed that you look at the railscast http://railscasts.com/episodes/250-authentication-from-scratch , it will give you an idea how to create authentication without forgetting some important steps.
Then you can use the gem devise which is an excellent authentication gem.
Have you tried putting your functions and everything for authentication within a Session Helpers file? Then, in your Application Controller if you add "include SessionsHelper" this should give you access to all the helper functions from Session that you should need