I'm using this gem for Facebook authentication in my Rails app.
I'm having some issues in IE and I think it's because of an issue in the Javascript in this file -
If you look at line 52, it seems I can pass options into channelUrl.
I'm implementing a login button like this -
<%= fb_login(:text=>"Log in") %>
Can I do this from my app, or do I need to edit the gem?
If I look at the README, you should have a partial like this one:
<%= fb_connect_async_js %>
<% if current_facebook_user %>
<%= "Welcome #{current_facebook_user.first_name} #{current_facebook_user.last_name}!" %>
or
<%= "Hello #{fb_name(current_facebook_user, :useyou => false)}!" # link to facebook profile %>
<%= fb_logout_link("Logout of fb", request.url) %><br />
<% else
# you must explicitly request permissions for facebook user fields.
# here we instruct facebook to ask the user for permission for our website
# to access the user's facebook email and birthday
%>
<%= fb_login(:text => 'Log in', :perms => 'email,user_birthday') %>
<% end %>
In that case, you just have to pass the options to fb_connect_async_js:
<%= fb_connect_async_js :channel_url => 'http://blahblah' %>
... rest of the partial ...
If your partial doesn't look like the one above, you should edit your question to post yours (the full one).
Related
I am working on an rails app in which there is one table Users, which has two roles Admin and member. Until now I am using single login page.
But now, I need to make two different login pages with completely different styling for admin and member.
Moreover Admin don't have sign_up option but member has.
I am totally confused that is it possible or not?
If possible, how to achieve this.
Devise sign in form is just a form with action matching to devise controller.
You can write this form code anywhere you like,
<%= form_for(:user, :url => session_path(:user)) do |f| %>
<%= f.text_field :email %>
<%= f.password_field :password %>
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
<%= f.submit 'Sign in' %>
<%= link_to "Forgot your password?", new_password_path(:user) %>
<% end %>
Adding to #maximus answer, you could use the Pundit gem to define your logged in :user action through a UserPolicy controller. Within this controller, you should be able to define which direction a passed in User navigates to defined by their logged in role.
https://github.com/elabs/pundit
I am trying to edit a micropost on the page without leaving the physical page.
In my app i have a page the renders all of a user's microposts using the partial below:
microposts/_micropost:
<%= render 'shared/edit_micropost', object: micropost %>
<%= micropost.title %>
<%= micropost.content %>
<%= micropost.url %>
<%= raw "Tags: #{micropost.tag_list.map {|t| link_to t.capitalize, tag_path(t)}}" %>
shared/edit_micropost:
<%= link_to "edit", object, remote: true %>
<%= form_for object do |object| %>
<%= object.text_field :title %>
<%= object.text_area :content %>
<%= object.text_field :url %>
<%= object.text_field :tag_list %>
<%= object.submit "Update", class: "btn btn-mini" %>
<% end %>
When I click "edit" I would like the form to come up so that the title, content, url, and tag_list of the specific micropost is editable.
Right now when I click "edit" I get No route matches [GET] "/microposts/452" I'm not sure how to specify a working path in my link_to. I assume I have to move the form_for to a JS file?
I'm new to programming and would really appreciate some help, thanks.
There is a gem maybe you want to try it, 'Best in Place' is a jQuery based AJAX Inplace-Editor
Also there is a screencast for it by Ryan Bates
A straightforward way to do this would be to go ahead and render the form on the page, but hide it with javascript. Then when the user clicks the button, show it again. This way the form is also available to users that don't have js enabled.
Then it's just a matter of setting the remote: true option in the form to get it to submit via ajax and use an ajax callback to notify the user of success or failure (if you want). Again, this approach will still allow non-js users to submit the form with a normal request, while users with js enabled will get the slick ajax functionality.
I am a three week old Rails newbie and I have something that I want to implement but have no idea how to go about it. I'm making an app:
I want a user to enter some sign-up info on the new users view page, then, when they click submit, instead of the user being created and saved in the database right away, instead I want them to be taken to a second webpage where they will be asked for some final verification before they can create their account. Then when they click 'verify' and the verification passes, the account is finally created and saved to the database.
This is hard for me because I only know how to make basic forms, where you enter info, hit submit, and you have a new entry in the database. I don't know how to defer the "user creation" for another webpage, but a friend has mentioned something about http requests, but I still don't know anything. I'll post some of my code so far:
My users_controller new definition:
def new
#user = User.new
#user.websites.build
end
My users_controller create method:
def create
#user = User.new(params[:user])
if #user.save
sign_in #user
flash[:success] = "Welcome!"
redirect_to #user
else
render 'new'
end
end
My users/new.html.erb sign up form:
<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
<%= render 'shared/error_messages' %>
<%= form_for(#user) do |f| %>
<%= f.label :email %>
<%= f.text_field :email %><br/>
<%= f.label :password %>
<%= f.password_field :password %><br/>
<%= f.label :password_confirmation, 'Confirm Password' %>
<%= f.password_field :password_confirmation %><br/>
<%= f.fields_for :websites do |builder| %>
<%= builder.label :url, 'Website URL' %>
<%= builder.text_field :url %>
<% end %>
<%= f.submit "Sign up", :id => 'submit' %>
<% end %>
I've never asked a question that's just asking for advice like this before, so I'm hoping this is the right place to ask. Any and all help is appreciated.
I think you are trying to create a "multistep" form...
There is a very good railscast about it: http://railscasts.com/episodes/217-multistep-forms?view=asciicast
However, you might face some validation problems, as you need to validate each step individually. So, take a look also here: http://guides.rubyonrails.org/active_record_validations_callbacks.html#conditional-validation
I hope it helps...
You'd better use Devise for user management.
https://github.com/plataformatec/devise
Here's a railscast tutorial.
railscasts.com/episodes/209-introducing-devise
If you're doing multistep, you can always pass information from one page to another. You can store it in a session array, repost it to the other page, or even make a cookie.
Remember to also do every step of this under https, because account creation requires sensitive info.
If Rails is your first I would actually recommend something lower level like PHP so you can understand how everything works before you start doing stuff with a high level framework like rails. MVC is usually not the best first step in web development, even though it is powerful and easier than doing everything from scratch.
I am a Devise fan and have used Devise for many of my Ruby on Rails applications .
I usually follow the below RailCasts for installing and customizing Devise .
http://railscasts.com/episodes/209-introducing-devise
http://railscasts.com/episodes/210-customizing-devise
The video tells us that if we want to customize the views , we need to run the below command -
rails generate devise:views
This creates the views related to authentication in the apps/views/devise folder . We can customize the look and feel .
My questions is - How do we allow multiple views for signing in ? For eg - I want to allow the user to be able to Login from the Root page itself by clicking a Login button on a navbar which leads to a modal box ( overlay / popup ) which allows the user to enter his login credentials , instead of having to visit the predefined pages generated by Devise.
You can have a look at the below link to see the project I am working on now .
http://squilio.heroku.com/ .
Try clicking on the Login button. I would like to have my signin form here .
the railscast episode you saw is too old ( Apr 12, 2010), latest Devise version is 2.0. so I think some of the features is deprecated.
For your question: If you want to have 2 different pages (e.g. 1 is a dialog/pop up by ajax, another is regular erb page), you have to implement 2 different actions, or at least you have to implement 2 different strategies for them. e.g.
# will render app/views/.../regular_login.html.erb
def regular_login
end
# render a dialog box only.
def dialog_login
render :layout => false
end
I found an elegant solution from this article ..
https://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app
It shows how we can achieve this by using form_for and posting to user_session_path
<%= form_for("user", :url => user_session_path) do |f| %>
<%= f.text_field :email %>
<%= f.password_field :password %>
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
<%= f.submit 'Sign in' %>
<%= link_to "Forgot your password?", new_password_path('user') %>
<% end %>
I am trying to create a link for user of my app to use to subscribe to their account calendars. I have a link that works that I generate in rails calendar_publisher_lists_url(:format => :ics, :only_path => false,:protocol => "web cal")
which generates a link like webcal://mywebsite.com/calendar.ics
However this only works if the user is logged in. I need for the link to work when the calendar is automatically updated, even if the user is not logged in. Thus I need to generate a link that would look like:
webcal://123#mywebsite.com/calendar.ics where '123' is the authentication token for the user.
How do I generate this url?
What's wrong with putting it onto the URL as attribute?
calendar_publisher_lists_url(:format => :ics, :only_path => false,:protocol => "webcal", :authentication_token => current_user.authentication_token)
webcal://mywebsite.com/calendar.ics?authentication_token=123
I mean apart from the security issue...
If security is not an issue you could change the route to add an id.
match '/calendar/:id/calendar_feed', to: 'calendar#calendar_feed', :as => 'calendar_feed_path'
Then in your controller put
def calendar_feed
#user=User.find(params[:id])
respond_to do |format|
format.ics
end
end
And then add a view template, adjust to fit your needs with your logic (this code is from one of my projects):
BEGIN:VCALENDAR
METHOD:PUBLISH
VERSION:2.0
PRODID:-//UserCalendar//EN
X-WR-CALNAME:Name Of Website
CALSCALE:GERGORIAN
<% #users.each do |user| %> #change logic to fit your needs
<% user.day_offs.each do |day_off| %>
BEGIN:VEVENT
DTSTAMP:<%=Time.now.strftime("%Y%m%dT%H%M%SZ")%>
UID:<%=day_off.id%>
SUMMARY:<%= day_off.user.name.titleize %> | <%= day_off.do_type %>
DTSTART:<%= day_off.start_date.strftime("%Y%m%d") %>
<% end_day=day_off.end_date + 1.day %>
DTEND:<%= end_day.strftime("%Y%m%d") %>
END:VEVENT
<% end %>
<% end %>
END:VCALENDAR
Then the feed link would be
<%= link_to("Subscribe to Calendar", "webcal://www.nameofwebsite.com/calendar_feed/#{current_user.user_id}/calendar_feed.ics" ) %>